TIL: Some surprising code execution sources in bash
https://yossarian.net/til/post/some-surprising-code-execution-sources-in-bash
TIL: Some surprising code execution sources in bash
https://yossarian.net/til/post/some-surprising-code-execution-sources-in-bash
@yossarian There's something magical about the array invocation and numerical evaluation. It doesn't even need the arithmetic:
guess 'a[$(cat /etc/passwd > /tmp/pwned)]'
(( num == 42 ))?![[ "${name}" == 42 ]] works correctly.@yossarian in this age it doesn't happen too often that someone says "surprising" in the title and whatever they're talking about is actually surprising in any way
but this genuinely is. and pretty scary
@kees @yossarian Do we need to do something about this?
$ git grep '\[\[.*\]\]' origin/master -- ':*.sh' | wc --lines
1065
edit: there is some amount of false positives from sed regexes embedded in shell scripts. but also enough real cases
@vegard @kees @yossarian more like git grep '\[' ...
at least for me the `oh bummer' part was the observation that [ also behaves this way, because in bash it's a builtin. perhaps that can actually be considered a bug?
@kees this itself is a TIL for me, since I was taught/received that [[ is newer than [!
but also, is this always true? [ and ‘test’ will also use eval if the builtin version gets used first, but I don’t know the rules around when the builtins are used vs. not (for my interactive shell, they seem to always have precedence)