| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# This file is part of util-linux. |
| 4 |
# |
| 5 |
# This file is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 2 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This file is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
|
| 15 |
# This test script is modified version of 'getopt-example.bash' example |
| 16 |
# file in misc/ directory. |
| 17 |
|
| 18 |
TS_TOPDIR="${0%/*}/../.." |
| 19 |
TS_DESC="basic" |
| 20 |
|
| 21 |
. "$TS_TOPDIR"/functions.sh |
| 22 |
ts_init "$*" |
| 23 |
|
| 24 |
ts_check_test_command "$TS_CMD_GETOPT" |
| 25 |
|
| 26 |
TEMP=$($TS_CMD_GETOPT -o ab:c:: --long a-long,b-long:,c-long:: -n 'example.bash' -- -a -b 1 -c2 --a-long --b-long 3 --c-long foo bar) |
| 27 |
|
| 28 |
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi |
| 29 |
|
| 30 |
eval set -- "$TEMP" |
| 31 |
|
| 32 |
while true ; do |
| 33 |
case "$1" in |
| 34 |
-a|--a-long) echo "Option a"; shift ;; |
| 35 |
-b|--b-long) echo "Option b, argument \`$2'"; shift 2 ;; |
| 36 |
-c|--c-long) |
| 37 |
case "$2" in |
| 38 |
"") echo "Option c, no argument"; shift 2 ;; |
| 39 |
*) echo "Option c, argument \`$2'"; shift 2 ;; |
| 40 |
esac ;; |
| 41 |
--) shift ; break ;; |
| 42 |
*) echo "Internal error!"; break;; |
| 43 |
esac |
| 44 |
done >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 45 |
|
| 46 |
echo "Remaining arguments:" >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 47 |
for arg do echo '--> '"\`$arg'" >> $TS_OUTPUT 2>> $TS_ERRLOG; done |
| 48 |
|
| 49 |
ts_finalize |