As I include more options, the command is getting longer and I want a way to simplify this, so that I can write the options I want excluded separately. In addition, I want to disregard if options are a combination of upper or lower case.
To try to do this I have tried the following. I try to include the exclusion pattern
one at a time, building the command. However this is not working very well due to unix expansion mechanism. I think I have tackled the upper and lower case combination, by using grep -i.
set excludeStr = "[-]-(quiet)"
set excludeStr = "${excludeStr}|(check)"
set excludeStr = "${excludeStr}|(shift=[0-9]+)"
set excludeStr = "${excludeStr}|((sort|group)=[0-9]+/[0-9]+(/[0-9]+)*)$)"
set strLst = `echo $argv[$firstArg-$lastArg] | tr ' ' '\n' \
| grep -ivE '$excludeStr' | tr '\n' ' '`
I would need a bit of assistance in using getopts. I had considered it long time ago but not been very good of using it in a way I want.
---------- Post updated at 08:33 AM ---------- Previous update was at 08:30 AM ----------
Ok, in my code I have he following. How would you tackle the procedure using getopts using ksh. My plan is to convert my scripts to ksh eventually.
# --Read Command Line Arguments---------------------------------------------------------------------
# Set echo to recognize both the -n flag and backslashed escape sequences
set echo_style = "both"
# Perform numeric calculations using bc.
alias MATH 'set \!:1 = `echo "\!:3-$" | bc -l`'
# --Read Command Line Arguments---------------------------------------------------------------------
set ierr = 0
set iarg = 0
set opt_chkColPos = 0
set opt_sortFlds = 0
set opt_groupTbl = 0
set opt_shiftTbl = 0
set opt_verbose = 0
set opt_quiet = 0
set opt_usage = 0
set opt_examples = 0
set opt_help = 0
set vrb_usrInputFlag = 0
set Def_vrbLevel = 1
set Def_shiftLen = 3
set arg_fullNamesLst = ""
set narg = $#argv
while ($iarg < $narg)
MATH iarg = $iarg + 1
set arg = $argv[$iarg]
set usrInputFlag = `echo $arg | awk '/=/ {print 1}; ! /=/ {print 0}'`
set opt = `echo $arg | awk 'BEGIN {FS="="} {print $1}' | tr '[:lower:]' '[:upper:]'`
set par = `echo $arg | awk 'BEGIN {FS="="} {print $2}'`
switch ($opt)
# -- Optional Arguments ------------------------------------------------------------------------
case "--CHECK": # Separates numbers from characters.
case "--CHECK-COLPOS":
set opt_chkColPos = 1
breaksw
case "--SORT":
case "--SORT-FIELDS":
set arg_sortPtn = $par
set opt_sortFlds = 1
breaksw
case "--GROUP":
case "--GROUP-TABLE":
set arg_groupPtn = $par
set opt_groupTbl = 1
breaksw
case "--SHIFT":
case "--SHIFT-TABLE":
set arg_shiftLen = $par
set opt_shiftTbl = 1
breaksw
case "-V":
case "--VRB-LEVEL":
set arg_vrbLevel = $par
set opt_verbose = 1
set vrb_usrInputFlag = $usrInputFlag
breaksw
case "-Q":
case "--QUIET":
set opt_quiet = 1
breaksw
case "-U":
case "--USAGE":
set opt_usage = 1
breaksw
case "-E":
case "--EXAMPLES":
set opt_examples = 1
breaksw
case "-H":
case "--HELP":
set opt_help = 1
breaksw
default:
set arg_fullNamesLst = "$arg_fullNamesLst $arg"
breaksw
endsw
end # while