The 'Shift' in shell scripts
Looking through a shell script today i came across a keyword ‘shift’ . The spontaneous attempt at deciphering the keyword led me to the concept of shifting command line arguments.
So essentially what the shift command does is- It takes the command line arguments and shifts them towrds the left by one place.
So if the command line arguments were :
$1 = -a $2 = foo $3 = bar
writing down shift would lead to the situation where :
$1 = foo $2 == bar
Now taking the live example of the NetBSD shell script . The shift command is written down as such :
case "$1" in "--shelltest") shelltest=true re_exec_allowed=false shift ;; "--no-re-exec") re_exec_allowed=false shift ;; esac
so essentially checking for a no-shell-test and then shifting all the rest of the arguments by one place.












