I'm trying to loop through an array and append a prefix to each value in the array. Simplified version of the code:
#!/bin/sh
databases=( db1 db2 db3 )
for i in live_${databases[@]} stage_${databases[@]}
do
....
done
However, it only prepends the prefix to the first value in the array - the values it loops through are:
live_db1 db2 db3 stage_db1 db2 db3
Any thoughts? Thanks.
databases=( db1 db2 db3 )
for i in ${databases[@]/#/live_} ${databases[@]/#/stage_}
do
....
done
Try something like this:
#!/bin/sh
databases="db1 db2 db3"
for i in $databases
do
x="live_$i"
y="stage_$i"
echo "$x $y"
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With