Danny van den Berg Danny van den Berg - 7 months ago 59
Bash Question

Unshift array element in Bash script

I would like to add elements to the beginning of an array instead of to the end. Is this possible in Bash?


You can use the "${array[@]}" syntax to achieve this:

array=('a' 'b' 'c');
echo "${array[@]}"; # prints: a b c
array=('d' "${array[@]}");
echo "${array[@]}"; # prints: d a b c