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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.