summaryrefslogtreecommitdiffstats
path: root/bash_experiments/cmd_options.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bash_experiments/cmd_options.sh')
-rwxr-xr-xbash_experiments/cmd_options.sh44
1 files changed, 44 insertions, 0 deletions
diff --git a/bash_experiments/cmd_options.sh b/bash_experiments/cmd_options.sh
new file mode 100755
index 0000000..e1b5656
--- /dev/null
+++ b/bash_experiments/cmd_options.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+echo $0
+echo $1
+
+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
+}
+
+Name=World
+
+#
+# The while-done structure defines a loop that executes once for each option
+# in the getopts - option structure. The ":h" string - which requires the quotes
+# - lists the possible input options that will be evaluated by the case - esac
+# structure. Each option listed must have a corresponding stanza in the case statement.
+# exit;; exits from the program without executing any more code even if some
+# exists. The option processing loop is also terminated, so no additional
+# options would be checked
+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"
+ echo $option
+ exit;;
+ esac
+
+done
+
+echo "Hello $Name"