Created
July 18, 2021 17:25
-
-
Save srikanthmanda/c9bd484e6682b43b05abc0d9ac208b41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Example: | |
# ./getopts-demo.sh -a42 -l Beeblebrox -c "Sector ZZ9 Plural Z Alpha" -f Zaphod | |
if [[ -z $1 ]] | |
then | |
echo 'Usage: ./getopts-demo.sh -f <first name> -l <last name> -a <age> -g <gender> -c <country>' | |
exit 1 | |
fi | |
while getopts ":f:l:a:g:c:" option | |
do | |
echo "option: ${option}" | |
echo "OPTIND: ${OPTIND}" | |
echo "OPTARG: ${OPTARG}" | |
case ${option} in | |
f ) echo "First name: ${OPTARG}" | |
;; | |
l ) echo "Last name: ${OPTARG}" | |
;; | |
a ) echo "Age: ${OPTARG}" | |
;; | |
g ) echo "Gender: ${OPTARG}" | |
;; | |
c ) echo "Country: ${OPTARG}" | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment