-
-
Save KhaledLela/620ce049e5c1dd0220d5953d8b67cb78 to your computer and use it in GitHub Desktop.
ScriptDefineParamWithHelpFunction
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 | |
helpFunction() | |
{ | |
echo "" | |
echo "Usage: $0 -d DOMAIN -n NAME" | |
echo "\t-d Root domain" | |
echo "\t-n Name/subdomain" | |
exit 1 # Exit script after printing help | |
} | |
while getopts ":d:n:" opt; | |
do | |
case "$opt" in | |
d ) DOMAIN="$OPTARG";; | |
n ) NAME="$OPTARG";; | |
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent | |
esac | |
done | |
# Print helpFunction in case parameters are empty | |
if [ -z "$DOMAIN" ] || [ -z "$NAME" ] | |
then | |
echo "Missing params"; | |
helpFunction | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment