3 ms·
> The following code changes the default behaviour of ls from listing > files to turning your terminal into an unstoppable steam locomotive. > The only
by laumars 14y ago
> The following code changes the default behaviour of ls from listing
> files to turning your terminal into an unstoppable steam locomotive.
> The only way to end it is closing the terminal, so use this with caution.
erm, that's easily stopped:
[ctrl]+z
$ pkill -9 sl
- eridius 14y ago^Z will just suspend `sl`, at which point bash will immediately launch another copy. That's what the loop is for.
- jlgreco 14y agoHave you actually tried it? In neither zsh nor bash does this seem to actually be the case.
- eridius 14y agoWell no, because I didn't want to install `sl`. But it looks like you're right. I just tried `while true; do ( echo hi; sleep 1; echo bye; ); done` and ^Z does stop the cycle.
- jlgreco 14y agoInterestingly, at least how I have zsh configured and don't have bash configured, the behavior of `fg` after suspending these is different. With zsh when I resume the execution it continues looping. However with bash it resumes for only one more iteration.
- eridius 14y agoYeah I would have expected `fg` to continue the loop, but it doesn't. If I put `echo $?` after the subshell in that loop, it doesn't even print when I run `fg`. It's like bash just throws away the loop entirely when I suspend the subshell.
- Evbn 14y agoYeah that's a famously annoying bug in bash.
- laumars 14y agoBash wont immediately launch another copy because the PID is still alive (even if it is stopped).
- tylermenezes 14y agoerm, no? "while true; sl; done"
- X-Istence 14y agoHold ctrl + c down, eventually sl will have quit, and bash will quit the while loop. I've never had issues quitting out of while true; do echo "stuff"; done for example.
- jlgreco 14y agozsh: suspended while true; do sl; done ?
- laumars 14y agoerm, yes. I suggest you try it before commenting next time.