Created
July 21, 2019 07:58
-
-
Save theycallmemac/f66b0afeca215df97869dd28612bea74 to your computer and use it in GitHub Desktop.
A short bash script to simulate a coinflip.
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 | |
FLIP=$(($(($RANDOM%10))%2)) | |
if [ $FLIP -eq 1 ];then | |
echo "heads" | |
else | |
echo "tails" | |
fi |
@srozanc-mcs ah, that works because the value returned by (()) is also the return code! (That must also be why the set
option to bail on any error may unexpectedly bail on a line that includes (()), depending on the result.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also to simply the conditional syntax by chaining boolean logic, and removing redundant syntax you can get it pretty clean: