Results 1 to 2 of 2
I am trying to implement getopts into my Bash script for passing command line arguments, yet I am encountering difficulty with the actual syntax and long options support. The man ...
- 04-15-2007 #1Just Joined!
- Join Date
- Oct 2005
- Posts
- 11
Passing long option arguments through getopts
I am trying to implement getopts into my Bash script for passing command line arguments, yet I am encountering difficulty with the actual syntax and long options support. The man for getopts did not include clear examples, so most examples came from other scripts on the net, which may not have the correct syntax. Please let know if long options are a possibility with getopts. Long options are the flags like --files or --verbose while shot options are -f or -v.
Code:GETOPT=$(getopts -o fdp:uvh -n ${SCRIPTNAME} -- "$@") if [ $? -ne 0 ]; then usage fi eval set -- "$GETOPT" while [ "$1" != "" ]; do case "$1" in -f | --files ) FLAG_FILES="true" ;; -d | --directories ) FLAG_DIR="true" ;; -p | --preset ) shift PRESET=$1 ;; -u | --undo ) FLAG_UNDO="true" ;; -v | --verbose ) VERBOSE="yes" ;; -h | --help ) usage exit ;; * ) usage exit 1 esac shift done
Bash return a /home/neville/bin/Filerenamer.sh: line 103: getopts: -o: invalid option. Please lead me to a syntax that support long options.
- 04-15-2007 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Searching for getopts in the forum shows more than 10 results, including http://www.linuxforums.org/forum/lin...tml#post405138 which has a few suggestions ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote