Skip to content

Instantly share code, notes, and snippets.

@juandm
Created August 17, 2021 15:39
Show Gist options
  • Save juandm/55b523788cc7e33a7f331d600e854ad4 to your computer and use it in GitHub Desktop.
Save juandm/55b523788cc7e33a7f331d600e854ad4 to your computer and use it in GitHub Desktop.
BashScriptWithOptions.sh
#!/bin/bash
############################################################
# Help #
############################################################
Help()
{
# Display Help
echo "Add description of the script functions here."
echo
echo "Syntax: scriptTemplate [-g|h|v|V]"
echo "options:"
echo "g Print the GPL license notification."
echo "h Print this Help."
echo "v Verbose mode."
echo "V Print software version and exit."
echo
}
############################################################
############################################################
# Main program #
############################################################
############################################################
# Set variables
Name="world"
############################################################
# Process the input options. Add options as needed. #
############################################################
# Get the options
while getopts ":hn:" option; do
case $option in
h) # display Help
Help
exit;;
n) # Enter a name
Name=$OPTARG;;
\?) # Invalid option
echo "Error: Invalid option"
exit;;
esac
done
echo "hello $Name!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment