From 6dbb979a88d8fef32b46eed133053938451420a4 Mon Sep 17 00:00:00 2001 From: Sotheareth Ham Date: Fri, 14 Aug 2020 14:07:57 +0700 Subject: [PATCH] add test sh file --- hello.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 hello.sh diff --git a/hello.sh b/hello.sh new file mode 100644 index 0000000..5c1ebff --- /dev/null +++ b/hello.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +helpFunction() +{ + echo "" + echo "Usage: $0 -a parameterA -b parameterB -c parameterC" + echo -e "\t-a Description of what is parameterA" + echo -e "\t-b Description of what is parameterB" + echo -e "\t-c Description of what is parameterC" + exit 1 # Exit script after printing help +} + +while getopts "a:b:c:" opt +do + case "$opt" in + a ) parameterA="$OPTARG" ;; + b ) parameterB="$OPTARG" ;; + c ) parameterC="$OPTARG" ;; + ? ) helpFunction ;; # Print helpFunction in case parameter is non-existent + esac +done + +# Print helpFunction in case parameters are empty +if [ -z "$parameterA" ] || [ -z "$parameterB" ] || [ -z "$parameterC" ] +then + echo "Some or all of the parameters are empty"; + helpFunction +fi + +# Begin script in case all parameters are correct +echo "$parameterA" +echo "$parameterB" +echo "$parameterC" + +echo "Press any key to continue" +while [ true ] ; do +read -t 3 -n 1 +if [ $? = 0 ] ; then +exit ; +else +echo "waiting for the keypress" +fi +done \ No newline at end of file