Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
OPTARG not being set?
- X-seq: zsh-users 2063
- From: Sweth Chandramouli <sweth@xxxxxxxxxxxxxxxxxxxx>
- To: ZSH Users <zsh-users@xxxxxxxxxxxxxxx>
- Subject: OPTARG not being set?
- Date: Tue, 2 Feb 1999 00:54:46 -0500
i have a function that i use to set any PATH-style variables,
which checks each token to be added to the pseudo-array to see if it
is already present, and also to see if it actually exists as a
directory, before adding it. by default, it takes its input and tries
to add it to PATH; since i originally wrote it for the korn shell
many years ago, before i knew about getopts, i had it use an ugly
if-then clause to accept a command-line argument of '-p VARIABLE'
so that it could be used to set other variables (like MANPATH,
LD_LIBRARY_PATH, etc.). i've finally gotten around to cleaning it
up, and as part of that, am trying to use getopts to set the
name of the variable to be set; i'm missing something, however,
because now it doesn't work.
this is the start of the function:
unset USER_SPECIFIED_PATH;
while getopts ":p" CMD_LINE_OPT ; do
case ${CMD_LINE_OPT} in
p ) USER_SPECIFIED_PATH=${OPTARG};;
\? ) print "unknown option \"-${OPTARG}\""
print 'usage: '
print 'addpath [-p PSEUDO_ARRAY] first_item:second_item:...:nth_item'
return 1
esac;
done;
after this loop finishes, however, USER_SPECIFIED_PATH is still
null. i've put some echo statements in the case clause for option p,
which confirm that OPTARG is never being set, even though CMD_LINE_OPT
is matching 'p'. does anyone have any idea why?
thanks,
sweth, who is still interested in maybe working on a proposal
for the zsh book, but is for now just cleaning up and commenting all
of his startup files to put on a web page.
--
Sweth Chandramouli
IS Coordinator, The George Washington University
<sweth@xxxxxxx> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F)
<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author