Blog is moving

My blog is moving to http://victormendonca.com/blog/. If you are looking for a specific or older post you are in the right place Otherwise check out my new page for more up to date content.

Sunday, March 29, 2009

Getting daily tips for bash


I still consider my self a new Linux user and a noobie. One of the things that I strive to learn is scripting in bash, but I do have difficulties as I have no programing background, so I try to read and get as much help as I can.

During my searches on the web I found a very interesting twitter profile for the author of “O'Reilly's Bash Cookbook”. He has daily updates with interesting bash tips, which I have found very useful.

So today I'll be providing a function script that can be added to your ~/.bashrc and used as either a command or a welcome message for you terminal emulator. This script will go to the twitter profile of “Bash cookbook” and download their daily content.

The script is compatible with links and elinks (Red Hat) for downloading the content. It creates 3 environment variables on your system to hold links version, last update and downloaded content.

Open you ~./bashrc with your favourite text editor and paste the lines bellow:
bash_tips ()
{
# checks for version of links
if [ -z "$LINKS_VERSION" ] ; then
export LINKS_VERSION=$(links -version | grep Links | cut -f1 -d" ")
fi

# checks variable that holds last update time
if [ "$BASH_TIPS_DATE" != $(date "+%d") ] ; then
export BASH_TIPS_DATE=$(date "+%d")
if [ "$LINKS_VERSION" = "ELinks" ] ; then
# script for ELinks
export BASH_TIPS=$(links -dump -dump-width 300 http://twitter.com/bashcookbook | egrep '^ *1\. [^http]' | sed 's/^ *//g')
else # script for Links
export BASH_TIPS=$(links -dump -width 300 http://twitter.com/bashcookbook | egrep '^ *1\. [^http]' | sed 's/^ *//g')
fi
fi

echo -e "\n## Today's bash tips ##\n$BASH_TIPS"
}

If you want to have the daily tips displayed when you open a terminal emulator, just add “bash_tips” to your ~/.bashrc.

This is what they will look like:
victux ~ $ bash_tips

## Today's bash tips ##
1. Using += on an array assignment adds new elements to the array. If RA has element 0-6 then RA+=(new elems) creates RA[7] and RA[8].10:24 PM Mar 27th from Identica


Book:
http://oreilly.com/catalog/9780596526788/
Twitter site:
http://twitter.com/bashcookbook
Official site:
http://www.bashcookbook.com/

No comments: