From: SQ on

I have $1, $2, $3 command line arguments that remain after a script is
called.

If the next script is called without command line arguments, these $1,
$2, $3
are still in the environment and are evaluated by getops. Is there any
way
to clear these positional arguments?

echo $1 $2 $3
-abc -def -ghi

$ unset 1
ksh: 1: is not an identifier

From: Stephane Chazelas on
On 27 Jan 2006 09:02:12 -0800, SQ wrote:
>
> I have $1, $2, $3 command line arguments that remain after a script is
> called.
>
> If the next script is called without command line arguments, these $1,
> $2, $3
> are still in the environment and are evaluated by getops. Is there any
> way
> to clear these positional arguments?
>
> echo $1 $2 $3
> -abc -def -ghi
>
> $ unset 1
> ksh: 1: is not an identifier
[...]

I don't understand your issue. But to clear the positionnal
parameters, you can either do:

shift "$#"

or

set --

If you want to make so that $2 now becomes $1 (and $3, $2...)
it's simply: shift

If you want to run getopts twice in a script with a different
set of positional parameters, remember to reset OPTIND to 1
(OPTIND=1).

--
Stephane
From: Chris F.A. Johnson on
On 2006-01-27, SQ wrote:
>
> I have $1, $2, $3 command line arguments that remain after a script is
> called.
>
> If the next script is called without command line arguments, these
> $1, $2, $3 are still in the environment and are evaluated by getops.
> Is there any way to clear these positional arguments?

Unless you a) source the next script, or b) place the arguments on
the command line, they will not be passed to another script.

> echo $1 $2 $3
> -abc -def -ghi
>
> $ unset 1
> ksh: 1: is not an identifier

To remove the first positional parameter ($1):

shift

To remove them all:

shift $#

Or use set:

set --

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence