Is it possible to use the variables passed to printf more than once in the formatting?
For example, with this line:
printf 'Hi %s, welcome to %s. %s is a great place to work. Thanks %s.' "John" "The Icecream Factory"
How can I "reuse" the first and second variables in printf?
I'm thinking something like:
printf 'Hi %s[1], welcome to %s[2]. %s[1] is a great place to work. Thanks %s[2].' "John" "The Icecream Factory"
... but obviously that's not it.
Desired output
Hi John, welcome to The Icecream Factory. The Icecream Factory is a great place to work. Thanks John.
Actual output
Hi John, welcome to The Icecream Factory. is a great place to work. Thanks .
Working environment is bash in Ubuntu 20.
printfformat characters support that. What's the reason you have to use%s? It's easier to define variables, which can be used multiple times in a String, e.g.n="John"; f="The Icecream Factory"; printf "Hi $n, welcome to $f. $f is a great place to work. Thanks $n."printfformat string: github.com/koalaman/shellcheck/wiki/SC2059echoinstead