| | |
getopts
![]() |
•
•
Join Date: Sep 2007
Posts: 25
Reputation:
Solved Threads: 0
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.
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:
bash Syntax (Toggle Plain Text)
while [ $1 ] ; do [ ${1:0:1} = '-' ] || break case ${1:1} in help) echo help;; c*) if [ ${1:1} ] ; then arg=${1:1} else shift; arg=$1 fi echo "arg of -c is $arg" ;; *) echo "bad option, $1";; esac shift done
![]() |
Similar Threads
- helps with getopts (Shell Scripting)
- comparing versions (Shell Scripting)
- Mail command (Shell Scripting)
- Help with getopt/getopts (Shell Scripting)
- execvp return help... (C)
Other Threads in the Shell Scripting Forum
- Previous Thread: is this perl doable in shell?
- Next Thread: Please it is very Important for me ....Please help me ...
| Thread Tools | Search this Thread |






