]>
cygwin.com Git - cygwin-apps/cygutils.git/blob - src/getopt/parse.bash
3 # A small example program for using the new getopt(1) program.
4 # This program will only work with bash(1)
5 # An similar program using the tcsh(1) script language can be found
8 # Example input and output (from the bash prompt):
9 # ./parse.bash -a par1 'another arg' --c-long 'wow!*\?' -cmore -b " very long "
11 # Option c, no argument
12 # Option c, argument `more'
13 # Option b, argument ` very long '
14 # Remaining arguments:
19 # Note that we use `"$@"' to let each command-line parameter expand to a
20 # separate word. The quotes around `$@' are essential!
21 # We need TEMP as the `eval set --' would nuke the return value of getopt.
22 TEMP
=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \
23 -n 'example.bash' -- "$@"`
25 if [ $?
!= 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
27 # Note the quotes around `$TEMP': they are essential!
32 -a|
--a-long) echo "Option a" ; shift ;;
33 -b|
--b-long) echo "Option b, argument \`$2'" ; shift 2 ;;
35 # c has an optional argument. As we are in quoted mode,
36 # an empty parameter will be generated if its optional
37 # argument is not found.
39 "") echo "Option c, no argument"; shift 2 ;;
40 *) echo "Option c, argument \`$2'" ; shift 2 ;;
43 *) echo "Internal error!" ; exit 1 ;;
46 echo "Remaining arguments:"
47 for arg
do echo '--> '"\`$arg'" ; done
This page took 0.034984 seconds and 5 git commands to generate.