Re:Bashttpd - An http server in bash
by gdb on Sunday September 16, 2012 @01:12PM
(#4529600)
You shouldn't have to sanitize if you quote your variables properly. If general, the rules for "$foo" are "parse first, expand afterwards" while those for $foo are "parse, expand, parse again", so
Note that you can't trivially inject a command this way, though you can inject arbitrary arguments:
I would recommend never using test ([) with more than three arguments. Once you start doing -a and -o, then people can inject confusing values for variables, making it impossible to parse:
Since test runs a subprocess, it can't tell the difference between data and arguments. Instead, you should do something like this:
(This also has the advantage of being way more legible.)
[ Parent
| on HN ]
Re:Bashttpd - An http server in bash
by michaelhoffman on Sunday September 16, 2012 @03:37PM
(#4530097)
You can also solve that problem with double square brackets:
[[ "$foo" = 1 && "$bar" = 2 ]]