no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | getopt [2013/08/27 22:47] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== getopt ====== | ||
| + | * [[bash]] | ||
| + | * [[getopts]] | ||
| + | * [[sh]] | ||
| + | |||
| + | Generally speaking, use '' | ||
| + | |||
| + | The man page has a good example, but here are some of the basics: | ||
| + | |||
| + | Use **-a:** to requires an argument, either directly after the '' | ||
| + | |||
| + | < | ||
| + | getopt a: $* | ||
| + | </ | ||
| + | |||
| + | Use **-b** to set a boolean value. | ||
| + | |||
| + | < | ||
| + | getopt b $* | ||
| + | </ | ||
| + | |||
| + | === getopt example === | ||
| + | |||
| + | <code bash> | ||
| + | # Allow -a < | ||
| + | args=`getopt a:vz $*` | ||
| + | |||
| + | # If getopt fails, then throw an error and quit | ||
| + | if [ $? -ne 0 ]; then echo " | ||
| + | |||
| + | # Set the new arguments | ||
| + | set -- $args | ||
| + | |||
| + | while true; do | ||
| + | case " | ||
| + | -a) | ||
| + | echo " | ||
| + | -v) | ||
| + | echo " | ||
| + | -z) | ||
| + | echo "Debug output enabled"; | ||
| + | --) | ||
| + | shift; break;; | ||
| + | esac | ||
| + | done | ||
| + | </ | ||