From 3099d3f9f367196c05820951f25a75116f0bbaaf Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Thu, 30 Dec 2021 15:04:09 +0100 Subject: Add getopts --- bash.md | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 -- cgit v1.2.3