Steve
Steve

Reputation: 175

Bash: Is ${@:2} the same as $2?

Is ${@:2} the same as $2 in Bash when my second argument is an array? My script does work with ${@:2} replaced by $2, but is there any downside?

Steve

Upvotes: 4

Views: 71

Answers (1)

glenn jackman
glenn jackman

Reputation: 246807

Not the same: "${@:2}" is the subset of the array beginning at index 2

$ set -- foo bar baz
$ printf "%s\n" "$2"
bar
$ printf "%s\n" "${@:2}"
bar
baz

Upvotes: 3

Related Questions