Danny van den Berg Danny van den Berg - 1 year ago 111
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?

Answer Source

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