diff options
Diffstat (limited to 'How to properly do options in a bash script with getopt!.md')
-rw-r--r-- | How to properly do options in a bash script with getopt!.md | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/How to properly do options in a bash script with getopt!.md b/How to properly do options in a bash script with getopt!.md new file mode 100644 index 0000000..7d417c5 --- /dev/null +++ b/How to properly do options in a bash script with getopt!.md @@ -0,0 +1,31 @@ +--- +tags: + - bash +--- +``` +#!/bin/bash + +while getopts "ab:c" opt; do + case "$opt" in + a) + echo "Option -a was specified." + ;; + b) + echo "Option -b was specified with argument: $OPTARG" + ;; + c) + echo "Option -c was specified." + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + esac +done + +shift $((OPTIND - 1)) + +echo "Remaining arguments: $@" +``` + +man bash // getopt
\ No newline at end of file |