Re:Escaping strings in Bash using !:q
by zeroimpl on Sunday October 04, 2020 @04:51PM
(#24682169)
Yes the example in the article and parent comments ought to be referred to as escaping, not quoting.
Most of the time, quoting with single quotes leads to something far easier on the eyes.
Here's an example function for quoting from stdin:
function bashquotesingle() {
printf "'";
sed "s/'/'\\\\''/g";
printf "'";
}
Here's an example function for quoting from stdin:
Though it does have a bug, at least on macOS, where sed adds a trailing newline. (See https://stackoverflow.com/questions/13325138/why-does-sed-ad...)