Last active
August 24, 2021 12:54
-
-
Save finesse-fingers/aff944f14aec0d60a392f033f89c6f07 to your computer and use it in GitHub Desktop.
How to parse cli args in a bash script
This file contains hidden or 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
# https://www.baeldung.com/linux/use-command-line-arguments-in-bash-script | |
# usage: <script> -u <username> -a <age> -f <fullname> | |
while getopts u:a:f: flag | |
do | |
case "${flag}" in | |
u) username=${OPTARG};; | |
a) age=${OPTARG};; | |
f) fullname=${OPTARG};; | |
esac | |
done | |
echo "Username: $username"; | |
echo "Age: $age"; | |
echo "Full Name: $fullname"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment