Skip to contentSkip to conversation

Printf %q

DISCUSSION Björn Bidar 2 participants 2 messages Mar 28, 2022

lore
Share & tools
lore
#0 lore raw

Hey,

Bash and Coreutils support print %q to quote a string for it to be used as shell input.

"%q ARGUMENT is printed in a format that can be reused as shell input,
escaping non-printable characters with the proposed POSIX $'' syntax."

Dash also supports the $' ' syntax used by this. Where was this proposed to POSIX?

Would it make sense to also support printf %q dash already supports $' '.

Br,

Björn Bidar

#1 lore raw
Quoted 1 line · Björn Bidar

Dash also supports the $' ' syntax used by this.

Does it? As far as I can see, dash does not support the $' ' syntax. With the $' ' syntax,

newline=$'\n'

assigns to newline a string of length 1 containing a newline character. In dash, what happens instead is that newline is assigned a string of length 3 containing the characters $, \, and n.

Tested with current master, commit 057cd650.

Cheers,
Harald van Dijk