2 ms·
In Bash, yes. Or, almost. The printf built-in command has a %q conversion specifier which quotes the argument such that the result can be used as input into th
by kazinator 3y ago
In Bash, yes. Or, almost.
The printf built-in command has a %q conversion specifier which quotes the argument such that the result can be used as input into the shell.
Such a thing cannot be inserted into a quote without affecting its meaning, but what you can do is terminate the quote before and after it.
'stuff before'$(printf "%q" "$value")'stuff after'
In this case, because it's a single quote, we need to terminate it anyway, order to activate the command substitution syntax.