Bash: whole array except the last element
1 answer
I'm not sure how much better it would be, but you can drop the arithmetic operator ( $(())
) and the starting index ( 0
here):
${a[@]::${#a[@]}-1}
So:
$ foo=( 1 2 3 )
$ echo "${foo[@]::${#foo[@]}-1}"
1 2
As you can see, the improvement is purely syntactic; the idea remains the same.
+5
source to share