Created
May 5, 2020 04:05
-
-
Save pacozaa/b37dc8f01662ac501ebac8437fde95fe to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
helpFunction() | |
{ | |
echo "" | |
echo "Usage: $0 -a parameterA -b parameterB -c parameterC" | |
echo -e "\t-a Description of what is parameterA" | |
echo -e "\t-b Description of what is parameterB" | |
echo -e "\t-c Description of what is parameterC" | |
exit 1 # Exit script after printing help | |
} | |
while getopts "a:b:c:" opt | |
do | |
case "$opt" in | |
a ) parameterA="$OPTARG" ;; | |
b ) parameterB="$OPTARG" ;; | |
c ) parameterC="$OPTARG" ;; | |
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent | |
esac | |
done | |
# Print helpFunction in case parameters are empty | |
if [ -z "$parameterA" ] || [ -z "$parameterB" ] || [ -z "$parameterC" ] | |
then | |
echo "Some or all of the parameters are empty"; | |
helpFunction | |
fi | |
# Begin script in case all parameters are correct | |
echo "$parameterA" | |
echo "$parameterB" | |
echo "$parameterC" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit: https://unix.stackexchange.com/questions/31414/how-can-i-pass-a-command-line-argument-into-a-shell-script