6

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
┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃
10

Use this:

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

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

┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃
┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃
┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃
|improve this answer|||||
  • ok, cheers that is what I have really been looking for... – nath Jan 6 '18 at 23:25
2
var="┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃   ┃"
printf '%s\n' "$var" "$var" "$var"
|improve this answer|||||
  • ok thanks, I hoped there was a way to concatenate the variables, but I can live with this... :-) – nath Jan 6 '18 at 23:12
  • @nath Maybe they can. I just don't understand what you intend. – Hauke Laging Jan 6 '18 at 23:18
  • sorry for being unclear, I thought my non-working-example would show that, but your approach is definitely good to know, the command is only getting a bit long when I would use {1..100}, but I did not ask this, really! – nath Jan 6 '18 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.