Skip to content

Instantly share code, notes, and snippets.

@ManasJayanth
Last active August 29, 2015 13:58
Show Gist options
  • Save ManasJayanth/10344552 to your computer and use it in GitHub Desktop.
Save ManasJayanth/10344552 to your computer and use it in GitHub Desktop.
Bash script to limit the number of times fortune-cowsay message is displayed at terminal start up
# Checking dependencies
command -v fortune >/dev/null 2>&1 ||
{ echo >&2 "I require fortune but it's not installed. Aborting."; exit 1; }
command -v cowsay >/dev/null 2>&1 ||
{ echo >&2 "I require cowsay too, but it's not installed. Aborting."; exit 1; }
# Set your counter limit here
COUNTER_LIMIT=7
FILE="$HOME/.counter.data"
if [ ! -f $FILE ]
then
echo 0 > $FILE
fi
count=`cat $FILE`
if [ $(($count % $COUNTER_LIMIT)) == 0 ]
then
fortune | cowsay
fi
count=`expr $count + 1`
echo $count > $FILE
@viggyprabhu
Copy link

I think the number should be random, it is more surprising when it appears when u least expect it. :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment