troubleshooting Question

Pl. explain what this unix shell script code (KSH) is doing...

Avatar of Katewadi
KatewadiFlag for United States of America asked on
Unix OS
3 Comments3 Solutions555 ViewsLast Modified:
1) I would like to know what this following shell code (written in KSH) is doing? I know it is is trying to retrieve program options from command line, but I am looking for explaination pertaining to the "while" and "case" loop. (tell me more about "getopts" and "OPTARG")

# The Code here...
# Initialize command line options
aflag=0
gflag=0
tflag=0
sflag=0
cflag=0
dogroup=none
dotype=none
doserv=none
passedlogfile=none
passederrfile=none

while getopts ag:t:s:cl:e: value
do
   case $value in
   a) aflag=1;;
   c) cflag=1;;
   g) gflag=1
      dogroup=$OPTARG;;
   t) tflag=1
      dotype=$OPTARG;;
   s) sflag=1
      dotype=`echo $OPTARG | cut -c1-2`
      doserv=$OPTARG;;
   l) passedlogfile=$OPTARG;;
   e) passederrfile=$OPTARG;;
   /?) echo "$0: Unknown option $OPTARG"
       printhelp
       exit 1;;
   esac
done

2) Is there a simpler way of doing this.

Thanks,

-Katewadi
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros