Reply

Join Date: Sep 2007
Posts: 25
Reputation: axn is an unknown quantity at this point 
Solved Threads: 0
axn axn is offline Offline
Light Poster

getopts

 
0
  #1
Jul 8th, 2009
while getopts htn: OPTION
do
        case ${OPTION} in
                t)  LIST='john mike smith' ;;
               n) LIST='rob peter joe' ;;
               h|*)  show_usage
                     exit 0
                     ;;
        esac
done
shift $(($OPTIND - 1))
args=$*

above is a snippet of code. i would like to use more than one character in my options e.g fname lname should count as 2 options instead of "while getopts htn: OPTION"
would like something like "while getopts fname lname: OPTION
How do i get getopts to work in that form.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: getopts

 
0
  #2
Jul 8th, 2009
See: http://www.mail-archive.com/bug-bash.../msg02546.html

I don't think getopts knows how to parse words as options (and not as non-GNU-style, certainly). You are probably better off writing your own parser, something like this:
  1. while [ $1 ] ; do
  2. [ ${1:0:1} = '-' ] || break
  3. case ${1:1} in
  4. help) echo help;;
  5. c*)
  6. if [ ${1:1} ] ; then arg=${1:1}
  7. else shift; arg=$1
  8. fi
  9. echo "arg of -c is $arg"
  10. ;;
  11. *)
  12. echo "bad option, $1";;
  13. esac
  14. shift
  15. done
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC