hello there I am back with more questions (sorry it is been quite a while since I had done scripting). I had tried the search function to search for the threads that might have an answer to my question, but I could not find it, so I had decided to post it.
I had created the scripts below in ksh (assume the ksh file name is abc.ksh)
--------------------------------------------------------------------------
var1=' '
var2=' '
while getopts ":a
" opt
do
case $opt in
a) var1=$OPTARG;;
b) var2=$OPTARG;;
\?) echo "Invalid argument"; exit 1;;
esac
done
shift 'expr ${OPTIND} - 1'
echo "Statement"
--------------------------------------------------------------------------
I ran the codes
--------------------------------------------------------------------------
Server temp-> abc.ksh -a some_value -b other_value
--------------------------------------------------------------------------
It works perfect, but if I ran the code with out the command line option
--------------------------------------------------------------------------
Server temp-> abc.ksh some_value other_value
Statement
--------------------------------------------------------------------------
I thought if there are no -a or -b option is given, getopts would automatically faults out and abc.ksh would just display "Invalid Argument" and exit. Did I not doing this section of scripts correctly or I am just plain missing something?
Thank you for your time