Created
May 9, 2012 20:33
-
-
Save logosity/2648596 to your computer and use it in GitHub Desktop.
Tail Recursion in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# warning you need to build in something to stop the loop | |
# in practice, I used a kill file check before invoking the script again | |
echo 'tail recursive bash ftw' | |
sleep 10 | |
$0 & | |
# if you didn't listen and ran this as-is, try: | |
# killall tail.sh | |
# or (assuming nothing else is running sleep): | |
# kill $(ps -f | grep sleep | grep -v grep | awk '{print $3}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Follow-up: The Racket developer Jay McCarthy has a good explanation of how exec works in "exec and Tail-call Optimization".