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');
Output: 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'
Output: bash: printf: $': invalid format character
I also tried using the local /usr/bin/printf
:
/usr/bin/printf '%2$s %2$s %1$s %1$s' 'World' 'Hello'
Output: /usr/bin/printf: %2$: invalid conversion specification
How to obtain the C
behavior in Bash? Thanks.
Edited:
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.
Edited:
E.g. think about GNU Bash source code internationalization. Very improbable without this feature.
printf
utility. This, obviously, doesn't magically make it work inbash
.