Danny van den Berg Danny van den Berg - 1 year ago 175
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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download