//View Tip #447
Similar Tips
» Find matching programs


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
[ $[ $RANDOM % 6 ] == 0 ] && echo Die || echo Live

Of course you can always replace "echo Die" by something a bit more interesting, kill a process perhaps or 'rm -rf' :)

View Comments »


Add your comment

Comments are currently disabled
David Delony
In case anyone's interested, here's my re-implementation in Python:

#! /usr/bin/env python
import random

choices = ['Live', 'Die']
print random.choice(choices)
Posted 2008-12-16 20:04:46
In case anyone's interested, your re-implementation is wrong.

There is a 1/6 chance of dying, not 1/2.

As for the original bash version, I would suggest replacing 'echo Die' with a simple 'exit', to terminate the current shell.
Posted 2009-01-30 17:37:41

btw (non-posix) but this can also be written as:

 (($RANDOM % 6)) && echo '*click*' || echo 'PUM!'
Posted 2009-02-13 00:44:03

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit