Danny van den Berg Danny van den Berg - 2 months ago 7x
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