Unseting positional parmaters from inside a program

Richard E. Covert covertr at force.UUCP
Fri Jan 19 09:19:21 AEST 1990


Does anyone know of a way to unset the positional parameters
from inside of a C program??

I have a program(setargs) in which I parse the command line. The output
of the program is captured in a Bourne shell script and saved in
a variable. The variable is then 'eval'ed. This allows me to assign
values to variables from within the shell script. The values are
builtin to the script returned from my program. AS an example:

UNIX>test_setargs -a -b "bs string"


____________________________ test_setargs __________________
#set -xv
args=`./setargs "ab:" "avar:bvar" "$@" `
#                ^^^^  ^^^^^^^^^
# like getopt() only setargs allows you to give values to variables
#
echo "args is $args"
echo "before the eval args statement"

echo "avar=$avar"
echo "bvar=$bvar"
echo "postparm1 = $1"
echo "postparm2 = $2"

eval $args

echo "after the eval args statement"


echo "avar=$avar"
echo "bvar=$bvar"
echo "postparm1 = $1"
echo "postparm2 = $2"


_______________ screen dump of test_setargs __________________
args is avar=1;bvar='bs string';set -- 
before the eval args statement
avar=
bvar=
postparm1 = -a
postparm2 = -b
after the eval args statement
avar=1
bvar=bs string
postparm1 = -a
postparm2 = -b
______________________________________________________________________
  
args is a shell variable containing the string out of my program. But, as you
see "avar" and "bvar" are set to their proper value but the positional p
parameters $1, and $2 still contain "-a" and "-b". The whole purpose of setargs
is to generate a string which is evaluated and sets values for variables.
But, I would like to clear $1 and $2 so that after running setargs $1 and
$2 would be cleared (as they were processed by setargs). So, if setargs processed all
of its positional parameters then the shell wouldn't have any values for $1, $2
etc after executing setargs.

Kinda complicated but setargs is great for parsing lines for variables.



-- 
 Richard E. Covert, Lead Engineer of Software Tools Group
 AG Communications Systems, Phoenix AZ   (602) - 581-4652
 TCP/IP: covertr at gtephx
 UUCP: {ncar!noao!asuvax | uunet!zardoz!hrc | att}!gtephx!covertr



More information about the Comp.lang.c mailing list