3 ms·
Bash feels more like a C buffer overflow vulnerability than a Lisp: When you're not careful your data tends to leak across its boundaries and get mixed up with
by ptx 2y ago
Bash feels more like a C buffer overflow vulnerability than a Lisp: When you're not careful your data tends to leak across its boundaries and get mixed up with your code.
Is there a way to quote data in Bash to safely insert it into a piece of code, the way you can in Lisp?
- kazinator 2y agoIn 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.