Operating System - HP-UX
1752598 Members
5605 Online
108788 Solutions
New Discussion

Re: unset positional parameter in shell

 
SOLVED
Go to solution
support_billa
Valued Contributor

unset positional parameter in shell

hello,

 

how can i unset positional parameter ?

 

unset a defined variable using the unset command:
unset variable_name

 

unset positional parameter ?

my proposal ? :

 

while [ $# -gt 0 ]
do
  shift
done

test:

 

set a b c
$ echo "$*"
abc

#positional parameters $1, $2,$3


while [ $# -gt 0 ]
do
  shift
done

 

echo "$*"

$

2 REPLIES 2
Matti_Kurkela
Honored Contributor
Solution

Re: unset positional parameter in shell

Your while-loop proposal can be simplified to:

shift $#

 

If you use the "set" command to set positional parameters, you should use "set -- <positional parameters>" to make sure you don't accidentally change any shell options.

 

An alternative way to unset all positional parameters would be:

set --

 

MK
Dennis Handly
Acclaimed Contributor

Re: unset positional parameter in shell

Typically you just use shift to march through your parms.  You can use "set -A" to copy the parms to an array and then you can fiddle with that array.  (Provided there are only 1023 parms.)

And then another "set -A" to restore the changed parms.

set -A SAVEARGS -- "$@"

The proper way to reset them is:
set -- "${SAVEARGS[@]}"

 

http://h30499.www3.hp.com/t5/Languages-and-Scripting/Shift-command/m-p/4133193