Created
August 17, 2021 15:39
-
-
Save juandm/55b523788cc7e33a7f331d600e854ad4 to your computer and use it in GitHub Desktop.
BashScriptWithOptions.sh
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 | |
############################################################ | |
# 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