Remove first element from $@ in bash [duplicate] Remove first element from $@ in bash [duplicate] bash bash

Remove first element from $@ in bash [duplicate]


Use shift?

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_07.html

Basically, read $1 for the first argument before the loop (or $0 if what you're wanting to check is the script name), then use shift, then loop over the remaining $@.


Another variation uses array slicing:

for item in "${@:2}"do    process "$item"done

This might be useful if, for some reason, you wanted to leave the arguments in place since shift is destructive.


firstitem=$1shift;for item in "$@" ; do  #process itemdone