m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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