Skip to content

Instantly share code, notes, and snippets.

@SahilC
Created December 9, 2014 10:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save SahilC/2767b6681539d96c4f37 to your computer and use it in GitHub Desktop.
Save SahilC/2767b6681539d96c4f37 to your computer and use it in GitHub Desktop.
A bash script to give you a random quote everytime you open your terminal. Add the following lines to your bashrc.
# font color : green
color='\e[0;32m'
# font color : white
NC='\e[0m'
getquote(){
num_online_quotes=9999
rand_online=$[ ( $RANDOM % $num_online_quotes ) + 1 ]
quote=$(wget -q -O - "http://www.quotationspage.com/quote/$rand_online.html" |
grep -e "<dt>" -e "</dd>" | awk -F'[<>]' '{
if($2 ~ /dt/)
{ print $3 }
else if($4 ~ /b/)
{ print "-- " $7 " n(" $19 ")"}
}')
}
i=1
color='\e[0;32m'
NC='\e[0m'
wget -q --spider http://google.com
if [ $? -eq 0 ]; then
while [ $i -lt 5 ]
do
getquote
echo "$quote" | grep ERROR > /dev/null
if [ $? -eq 0 ];then
getquote
i=`expr $i + 1`
else
break
fi
done
else
a=`date|cut -c 19`
var=(" Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better.
\n \t\t\t\t\t\t\t-Samuel Beckett " "Never give up, for that is just the place and time that the tide will turn.
\n \t\t\t\t\t\t\t-Harriet Beecher Stowe " "Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.
\n \t\t\t\t\t\t\t-Thomas A. Edison" "Life isn't about getting and having, it's about giving and being.
\n \t\t\t\t\t\t\t-Kevin Kruse" "Strive not to be a success, but rather to be of value.
\n \t\t\t\t\t\t\t-Albert Einstein" "You miss 100% of the shots you don't take.
\n \t\t\t\t\t\t\t-Wayne Gretzky" "People who are unable to motivate themselves must be content with mediocrity, no matter how impressive their other talents.
\n \t\t\t\t\t\t\t-Andrew Carnegie" "Design is not just what it looks like and feels like. Design is how it works.
\n \t\t\t\t\t\t\t-Steve Jobs" "Only those who dare to fail greatly can ever achieve greatly.
\n \t\t\t\t\t\t\t-Robert F. Kennedy" "All our dreams can come true, if we have the courage to pursue them.
\n \t\t\t\t\t\t\t-Walt Disney " "Success consists of going from failure to failure without loss of enthusiasm.
\n \t\t\t\t\t\t\t-Winston Churchill" )
quote="${var[$a]}"
# Welcome message ! Edit it with your name
#end of code
fi
echo -e "${color}"
echo "**************** Welcome back Sahil! *****************"
echo -e "\n"
echo -e "$quote" | sed 's/n()//g'| xargs -0 echo | fmt -80
echo -e "${NC}"
@harrys1987
Copy link

hi test

@SamroodAli
Copy link

Thank you

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