3 ms·
The Bash example is simply wrong: #!/bin/bash ./$0|./$0& # $0 is the name of the shell script itself There is no need for the leading ./ if the script
by account42 5y ago
The Bash example is simply wrong:
#!/bin/bash
./$0|./$0& # $0 is the name of the shell script itself
There is no need for the leading ./ if the script was invoked via a relative path ($0 will already have it) and adding it will break it if the script is invoked via an absolute path or name that is resolved against $PATH.
Further, what $0 holds is only a convention and up to the caller. If you are already restricting yourself to Bash, used ${BASH_SOURCE[0]} to always get the path to the script file.
But really, there is no need for a separate Bash version when the classic POSIX sh fork bomb already covers it (included in the repo as fork-bomb.sh):
:(){:|:&};:
- archduck 5y agoYou'll get a syntax error if you try to run that - braces need spaces. https://stackoverflow.com/questions/21186724/why-is-whitespace-sometimes-needed-around-metacharacters https://stackoverflow.com/questions/21186724/why-is-whitespa... (The link here doubles as an explanation and as a warning to anyone thinking about getting a forkbomb tattoo.)