![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using getopts | TurboArkhan | Shell Programming and Scripting | 3 | 06-22-2009 04:31 PM |
| Help in getopts | chella | Shell Programming and Scripting | 4 | 11-02-2007 01:09 AM |
| getopts help | GrepMe | Shell Programming and Scripting | 3 | 06-20-2007 11:47 AM |
| help in getopts | problems | Shell Programming and Scripting | 1 | 05-04-2006 11:07 PM |
| getopts | Shell Programming and Scripting | 3 | 12-05-2002 07:42 PM | |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
ksh: can you use getopts in a function?
I wrote a script that uses getopts and it works fine. However, I would like to put the function in that script in a startup file (.kshrc or .profile). I took the "main" portion of the script and made it a function in the startup script. I source the startup script but it doesn't seem to parse through the getopts case.
So my question is if using getopts in a function is even valid? Thanks. |
|
||||
|
See if anybody can figure this out...
I have a number of functions in .bashrc
One function I'll call hctinfo() and it is considered by me to be the "main" part of my set of functions. It calls other functions depending on the options (handled by getopts. Looks like this: Code:
version()
{
...
}
usage()
{
...
}
help()
{
...
}
getAdminStatus()
{
...
}
getOperStatus()
{
...
}
getDescription()
{
...
}
getImage()
{
...
}
getGroup()
{
...
}
getMod()
{
...
}
getPackages()
{
...
}
hctinfo()
{
ADMIN_STAT=0
GROUP=0
IMAGE=0
DESC=0
MOD=0
OPER_STAT=0
PACKS=0
OPTSTRING=":aAdDhHiIgGmMoOpPvV"
while getopts ${OPTSTRING} option
do
case ${option} in
h|H) help
return 0;;
v|V) version
return 0;;
a|A) printf "ADMIN_STAT=1\n"
ADMIN_STAT=1;;
i|I) IMAGE=1;;
g|G) GROUP=1;;
d|D) DESC=1;;
m|M) MOD=1;;
o|O) OPER_STAT=1;;
p|P) PACKS=1;;
?) printf "\nWTF? Way to go, dumbass.\n\n"
usage
return 1;;
esac
done
shift $(($OPTIND - 1))
...
...
}
Code:
$ . ./.bashrc Sun Microsystems Inc. SunOS 5.10 Generic January 2005 \nWorking directory is /dvs/dncs\nDatabase is dncsdb\n [14:00:22]$ hctinfo -a 00:40:7B:E1:AB:66 ADMIN_STAT=1 Deployed [14:00:26]$ hctinfo -a 00:40:7B:E1:AB:66 [14:00:32]$ Somehow the options, options count, etc... (everything associated with getopts) needs to get reset. Any ideas? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|