Resetting positional parameters

In certain situations, we may need to reset original positional parameters.

Let's try the following:

$ set Alan John Dennis

This will reset the positional parameters.

Now $1 is Alan, $2 is John, and $3 is Dennis.

Inside scripts, we can save positional parameters in a variable, as follows:

oldargs=$*

Then, we can set new positional parameters.

In addition, we can bring back our original positional parameters, as follows:

set $oldargs

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.