Last active
June 21, 2021 08:02
-
-
Save tevino/e390f186c77e4a39811fbb0d4fe18366 to your computer and use it in GitHub Desktop.
A simulation of The Ultimate Machine built by Claude Shannon https://en.wikipedia.org/wiki/Useless_machine
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 | |
IS_ON=0 | |
loading(){ | |
for _ in {1..3}; do | |
printf '.' | |
sleep 0.2 | |
done | |
} | |
handle_usr1(){ | |
((IS_ON^=1)) | |
} | |
work(){ | |
printf "\n => Sending USR1 to %d" $$ | |
loading | |
kill -USR1 $$ | |
printf "\n" | |
} | |
main() { | |
printf "This is a simulation of The Ultimate Machine built by Claude Shannon\n" | |
printf "https://en.wikipedia.org/wiki/Useless_machine\n" | |
printf "\n" | |
printf "Usage:\n" | |
printf " Send USR1 to this process(%d) to toggle the switch:\n" "$$" | |
printf " kill -s SIGUSR1 %d\n\n" "$$" | |
trap 'handle_usr1' USR1 | |
while true; do | |
printf "\rThe Ultimate Machine is " | |
if [[ $IS_ON != 0 ]]; then | |
printf "ON " | |
work | |
else | |
printf "OFF" | |
fi | |
sleep 0.1 | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment