Bash – Brace expansion with elements of an array

bashbrace-expansion

In Bash we can already do this:

echo foo.{a,b,c}
# == foo.a foo.b foo.c

How do we get roughly:

arr=(a b c)
echo foo.{${arr[@]}}
# == foo.a foo.b foo.c

Best Answer

You can use parameter expansion

$ arr=(a b c)

$ echo "${arr[@]/#/foo.}"
foo.a foo.b foo.c
Related Question