Skip to content

Instantly share code, notes, and snippets.

@KhaledLela
Created November 8, 2021 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KhaledLela/620ce049e5c1dd0220d5953d8b67cb78 to your computer and use it in GitHub Desktop.
Save KhaledLela/620ce049e5c1dd0220d5953d8b67cb78 to your computer and use it in GitHub Desktop.
ScriptDefineParamWithHelpFunction
#!/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