Bash – Repeat a variable with printf

bashprintfshell-scriptvariable

if I use the following command:

printf "%.0s┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃\n" {1..3}

I get an output like this:

┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃
┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃
┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃

How can I achieve the same result with getting the repeated chars from a variable?

I tried this approach:

var="┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃"
printf '%.0s%s\n' {1..3} "$var"

but it does not work, I end up with this:

2
┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃

Best Answer

Use this:

$ var="┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃"

$ printf "$var"'%.0s\n' {1..3}

┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃
┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃
┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃
Related Question