3 ms·
[[...]] is non-portable and has an extremely quirky corner case with variable expansion in arithmetic contexts, what's not to love?
by PhilipRoman 9mo ago
[[...]] is non-portable and has an extremely quirky corner case with variable expansion in arithmetic contexts, what's not to love?
- ndsipa_pomu 9mo agoI'm intrigued - any info on that? I personally use ((...)) for arithmetic tests and [[...]] for all other tests as I just target new versions of BASH and don't care much about POSIX compatibility.
- PhilipRoman 9mo agoThis is completely safe: [ "${payload}" -eq 42 ] This can evaluate arbitrary code: [[ "${payload}" -eq 42 ]] Here is one example of a malicious payload: payload='a[$(touch /tmp/pwned)]'
- ndsipa_pomu 9mo agoThanks. Now I need to figure out whether (( payload == 42 )) is safe.
- ndsipa_pomu 9mo agoIt appears not.
- account42 9mo agoIt also does wildcards though, with POSIX you'll need a case statement for that.