3 ms·
> One nice thing about bash is the ${var@Q} syntax that is great for printing stuff and deals with the potential for stuff that affects the terminal in a much n
by Calzifer 3y ago
> One nice thing about bash is the ${var@Q} syntax that is great for printing stuff and deals with the potential for stuff that affects the terminal in a much nicer way than piping through tr.
An alternative which works in both Bash and Zsh is
printf %q "$var"
using /usr/bin/printf %q "$var" has even a good chance to work in other shells.
And as fun fact: the Zsh equivalent for Bash's ${var@@} is ${(q)var} and it was not enough to have one quoting style but instead you can also provide qq, qqq, qqqq, q+ or q- all with a different result.
https://zsh.sourceforge.io/Doc/Release/Expansion.html#Parameter-Expansion-Flags https://zsh.sourceforge.io/Doc/Release/Expansion.html#Parame...