Skip to content

Instantly share code, notes, and snippets.

@theycallmemac
Created July 21, 2019 07:58
Show Gist options
  • Save theycallmemac/f66b0afeca215df97869dd28612bea74 to your computer and use it in GitHub Desktop.
Save theycallmemac/f66b0afeca215df97869dd28612bea74 to your computer and use it in GitHub Desktop.
A short bash script to simulate a coinflip.
#!/bin/bash
FLIP=$(($(($RANDOM%10))%2))
if [ $FLIP -eq 1 ];then
echo "heads"
else
echo "tails"
fi
@pmarreck
Copy link

pmarreck commented Jan 5, 2023

@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