A few months ago I tattooed a fork bomb on my arm, and I skipped the whitespaces, because I think it looks nicer without them. But to my dismay, sometimes (not always) when I run it in a shell it doesn't start a fork bomb, but it just gives a syntax error.
bash: syntax error near unexpected token `{:'
Yesterday it happened when I tried to run it in a friend's Bash shell, and then I added the whitespace and it suddenly worked, :(){ :|:& };:
instead of :(){:|:&};:
Does the whitespace matter; have I tattooed a syntax error on my arm?!
It seems to always work in zsh, but not in Bash.
A related question does not explain anything about the whitespaces, which really is my question; Why is the whitespace needed for Bash to be able to parse it correctly?
Bash indenting is very sensitive to characters. For example a space behind “do” in while/for loops will throw it of. When you have nested loops this is very ugly, and makes it hard to follow the code.
There is a list of characters that separate tokens in BASH. These characters are called metacharacters and they are |
, &
, ;
, (
, )
, <
, >
, space and tab. On the other hand, curly braces ({
and }
) are just ordinary characters that make up words.
Omitting the second space before }
will do, since &
is a metacharacter. Therefore, your tattoo should have at least one space character.
:(){ :|:&};:
Just tattoo a
#!/bin/zsh
shebang above it and you'll be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With