Preamble. I know that in the
C language, the
printf function allows to do this:
printf('%2$s %2$s %1$s %1$s', 'World', 'Hello');
Hello Hello World World
But in GNU Bash it seems this feature is not supported:
printf '%2$s %2$s %1$s %1$s' 'World' 'Hello'
bash: printf: $': invalid format character
I also tried using the local
/usr/bin/printf '%2$s %2$s %1$s %1$s' 'World' 'Hello'
/usr/bin/printf: %2$: invalid conversion specification
How to obtain the
C behavior in Bash? Thanks.
I was curious about this behaviour, I can't accept a workaround that changes the order of the arguments. It should work just playing with the format string.
E.g. think about GNU Bash source code internationalization. Very improbable without this feature.