In embracing %b I was thinking of some not-so-common, but very possible cases, such as the example below. printf %b seems to be the most portable and error free of the four options.MochiMoppel wrote:Well, yes, %b is correct but redundant, %s would be wrong, it would not even expand the "\n"s that separate the variables since the whole argument is one big string and it doesn't matter if the "\n"s are in the variables or between them. Just try it. The only difference to echo -e is that there is no final linefeed, making find "some_string" the same as echo -en "some_string". Only if you want to emulate echo -e you would need %b. The whole thing then would have to look like this: printf "%b\n" "some_string_with_escape_codes_in_it" . Confused? I hope not.step wrote:I think my original intent was to output all "\n"s as newlines, including the "\n"s that are stored in $MULTILINE, so %b is correct (you were).
%s instead would only expand the "\n"s that separate the variables in printf %s "$MULTILINE\n$TYPELESS\n$FONT\n$COLOUR".
Code: Select all
# echo -e '%s\n%'
%s
%
# printf '%s\n' '%s\n%'
%s\n%
# printf '%b\n' '%s\n%'
%s
%
# printf '%s\n%'
sh: printf: `%': missing format character
#