Skip to content

Instantly share code, notes, and snippets.

@finesse-fingers
Last active August 24, 2021 12:54
Show Gist options
  • Save finesse-fingers/aff944f14aec0d60a392f033f89c6f07 to your computer and use it in GitHub Desktop.
Save finesse-fingers/aff944f14aec0d60a392f033f89c6f07 to your computer and use it in GitHub Desktop.
How to parse cli args in a bash script
# 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