Reminds me of my rather memorable introduction to special characters invoking functions, seeing this dastardly little quip in the email signature of someone in a mailing list (circa '95 or so). :(){:|:&};: My curiosity piqued, I pasted it into the shell on my terminal in a pure example of FAFO. The poor little Sparc 5 I was using ground to a halt over the course of about ten seconds. The reboot was as hard as the les…
Something I never understood about this: is the pipe necessary, or just to have another symbol contributing to the mayhem? :(){:&;:};: This is the same number of characters but doesn’t use a pipe, and I was never able to figure out why it seems so universally to use a pipe.
Test your square brackets
61–68 of 68 posts
Re: Test your square brackets
#62bash is a UNIX legacy tool from the 80s that lingers on in software written today because it's part of the POSIX standard (well, sh, which is close enough), and because generations of developers on UNIX-like systems can be assumed to be familiar with it. I don't think this is a good thing, and I would like to see active efforts to replace the use of bash with better, more-modern scripting languages that provide an easier-to-understand more-reliable experience for users.
Re: Test your square brackets
#63Earlier quoted context omitted.
[[...]] is non-portable and has an extremely quirky corner case with variable expansion in arithmetic contexts, what's not to love?
I'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.
This can evaluate arbitrary code: [[ "${payload}" -eq 42 ]]
Here is one example of a malicious payload:
payload='a[$(touch /tmp/pwned)]'Re: Test your square brackets
#64Earlier quoted context omitted.
I'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.
This 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)]'
Now I need to figure out whether (( payload == 42 )) is safe.
Re: Test your square brackets
#65Earlier quoted context omitted.
> The reboot was as hard as the lesson. I'm confused. What happened on reboot?
A hard reboot is where the power goes all the way off, a soft reboot is where it doesn't. A fork bomb makes it very hard / impossible to trigger a soft reboot, forcing you to do a hard reboot. As an extra sting, a hard reboot can be damaging if the software and hardware is not correctly handling power interruption, which was much more likely in the 90's.
Re: Test your square brackets
#66Earlier quoted context omitted.
You mean shellcheck will detect when single brackets won't be enough? I've also just defaulted to double because I never really looked into it
Yeah, if you set the shebang `#!/bin/sh` (which is portable), shellcheck will complain about double brackets. It also helps you do quoting correctly when using single brackets.
And this isn't meant snarkily - why should I care if my scripts are portable? I've worked on a number of different devices and types but have seemingly always had access to bash.
Re: Test your square brackets
#67Earlier quoted context omitted.
This 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)]'
Thanks. Now I need to figure out whether (( payload == 42 )) is safe.
Re: Test your square brackets
#68Reminds me of my rather memorable introduction to special characters invoking functions, seeing this dastardly little quip in the email signature of someone in a mailing list (circa '95 or so). :(){:|:&};: My curiosity piqued, I pasted it into the shell on my terminal in a pure example of FAFO. The poor little Sparc 5 I was using ground to a halt over the course of about ten seconds. The reboot was as hard as the les…
Something I never understood about this: is the pipe necessary, or just to have another symbol contributing to the mayhem? :(){:&;:};: This is the same number of characters but doesn’t use a pipe, and I was never able to figure out why it seems so universally to use a pipe.