In bash
, this syntax can be used to get list of command line arguments, starting from $2
:
echo "${@:2}"
This syntax does not seem to work in sh
(/bin/dash
).
What would be the best way to emulate this in sh ?
(shift; echo "$@")
Using the subshell created by the parens ensures that "$@"
in the outer scope is not modified.
As another approach (uglier, but avoiding the need for a subshell), you can remove the first argument, and re-add it later:
argOne=$1 # put $1 in $argOne
shift # rename $2 to $1, $3 to $2, etc
echo "$@" # Pass the new argument list to echo
set -- "$argOne" "$@" # Create a new argument list, restoring argOne before the rest