The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 03-17-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
As a remark on design, perhaps they should not be "options" if they are mandatory.

After the while loop, check if password or config file is unset, and die if it is?

I don't think there's a standard way to get long options with getopts; you can roll your own, though.


Code:
while :
do
  case $# in 0) break;; esac
  case $1 in 
    -h|-\?|--help) usage;;
    -d|--debug) DEBUG=true;export SCRIPT_LOG_LEVEL=DEBUG; shift ;;
    -t|--type) DEVTYPE="$2"; shift; shift ;;
    -s|--socks) SIG_IP="$2"; export SOCKS5_SERVER="$2:9001"; shift; shift ;;
    -l|--login) HOST_LOGIN="$2"; shift; shift;;
    -p|--password) PASSWORD="$2"; shift; shift ;;
    -f|--config-file) cl_cfile_specd=1
        export RUNNING_CONFIG_FILE="$2"; shift; shift ;;
    -*) logmsg "Unrecognized param usage";;
  esac
done

Making it die gracefully when an option which requires an argument doesn't receive any (i.e. $2 is not set at all) is left as an exercise. The problem of seeing that $2 is the next option is artificial intelligence (or you could invent a separate mechanism for specifying an argument which begins with dash, so that you can forbid option arguments to start with a dash in the general case. I don't know if that's good or bad usability).