Use of Shift command

Hello Expert

Can any one please explain what is the use of shift command in general terms:

set -- $(ls -t)
	shift
	rm -Rf $*

what is the use of shift command over here.

Thanks a lot for your help

Try this to get the concept...

[root@bt] $ cat run
#!/bin/bash

set -- "1" "2" "3" "4" "5"
echo $*
shift
echo $*
shift
echo $*
shift
echo $*

Output

[root@bt] $ ./run
1 2 3 4 5
2 3 4 5
3 4 5
4 5

It will shift the arguments from right to left
Lets say, you have 3 arguments i.e. $1=a, $2=b, $3=c
Now you "shift" and try priting $1, it will print "b" and $2 will be "c" and there will no $3

HTH
--ahamed

1 Like

Awesome!!!! Thanks a lot