m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <m@m-chrzan.xyz>2021-12-30 15:04:09 +0100
committerMarcin Chrzanowski <m@m-chrzan.xyz>2021-12-30 15:04:09 +0100
commit3099d3f9f367196c05820951f25a75116f0bbaaf (patch)
treedd8755c43aaf41b206bbd7905ff6e1a8fa276b84
parenta664862cda9ab53dad57b23ebf4c1374495d7043 (diff)
Add getopts
-rw-r--r--bash.md11
1 files changed, 11 insertions, 0 deletions
diff --git a/bash.md b/bash.md
index e342625..12312c6 100644
--- a/bash.md
+++ b/bash.md
@@ -77,3 +77,14 @@ All keys:
${!array[*]}
${!array[@]}
+
+## Getopts example
+
+ while getopts 'a:b:c' flag; do
+ case "${flag}" in
+ a) do_something $OPTARG ;;
+ b) b_option=$OPTARG ;;
+ c) c_flag=1 ;;
+ *) error "Unexpected option ${flag}" ;;
+ esac
+ done