Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

unset positional parameter in shell

SOLVED
Go to solution
Highlighted
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
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