Alex Rivera | Logout

Getting all elements of a bash array except the first

Asked 2011-06-09T02:22:46.193
43

I have an indexed bash array and I'd like to use an expression like "${a[@]}" except I want it to not include a[0]. The best that I can think of is this:

j=0
for i in "${a[@]}"
do
    b[j]=${a[++j]}
done

and then use "${b[@]}". Is there a better way?

Edit
Report

1 Answer

74
$ a=(1 2 3)
$ echo "${a[@]:1}"
2 3
answered 2011-06-09T02:24:51.340

Your Answer