BASH: cool functions for your .bashrc file

0 Likes

Many times I prefer to just work from the shell. I wrote some functions
for my .bashrc file that I thought I would share.


The .bashrc file is a great place to put functions if your using them
regularly. Alternatively, you could alias the programs but since they are
small, I don't mind putting them in the .bashrc file just to keep it
simple.



Here are a few of the functions I wrote.



weather ()

stock ()

translate ()

define ()



Probably these are self explanatory but just in case they are not......



weather

Weather by us zip code - Can be called two ways # weather 50315 # weather

"Des Moines"



[14:33:09 crouse]$ weather 50317
Weather for Pleasant Hill, IA 19F Light Snow Wind: N at 16 mph Humidity: 80%
[~]
[14:39:35 crouse]$ weather "Des Moines"
Weather for Des Moines, IA 19F Blowing Snow Wind: N at 21 mph Humidity: 74%
[~]
[14:40:03 crouse]$

-----------------------



stock

Stock prices - can be called two ways. # stock novl (this shows stock
pricing) #stock "novell" (this way shows stock symbol for novell)



[14:39:25 crouse]$ stock "novell"
NOVL NOVELL INC NasdaqGS Security Software & Services
[~]
[14:39:32 crouse]$ stock novl
NOVELL INC (NasdaqGS:NOVL) - delayed quote.
Last Trade: 7.10 Change: 0.00 (0.00%) 52wk Range: 5.70 - 9.83
[~]
[14:39:35 crouse]$

-----------------------


translate

Translate a Word - USAGE: translate house spanish # See dictionary.com
for available languages (there are many).



[~]
[14:40:03 crouse]$ translate house spanish
"house" in Spanish: casa
[~]
[14:40:52 crouse]$ translate house german
"house" in German: das Haus
[~]
[14:40:59 crouse]$ translate house french
"house" in French: maison
[~]
[14:41:06 crouse]$

-----------------------


define

Define a word - USAGE: define dog



[~]
[14:41:06 crouse]$ define dog
* a member of the genus Canis (probably descended from the common
* frump: a dull unattractive unpleasant girl or woman
* informal term for a man
[~]
[14:41:47 crouse]$ define canine
* of or relating to a pointed conical tooth
* one of the four pointed conical teeth (two in each jaw) located
* any of various fissiped mammals with nonretractile claws and
[~]
[14:41:54 crouse]$


coolfunctions.txt



# <--------- Cool Functions by Crouse-------->
# Cool Functions for your .bashrc file.

# Weather by us zip code - Can be called two ways # weather 50315 # weather "Des Moines"
weather ()
{
declare -a WEATHERARRAY
WEATHERARRAY=( `lynx -dump "http://www.google.com/search?hl=en&lr=&client=firefox-a&rls=org.mozilla:en-US:official&q=weather ${1}&btnG=Search" | grep -A 5 -m 1 "Weather for"`)
echo ${WEATHERARRAY[@]}
}

# Stock prices - can be called two ways. # stock novl (this shows stock pricing) #stock "novell" (this way shows stock symbol for novell)
stock ()
{
stockname=`lynx -dump http://finance.yahoo.com/q?s=${1} | grep -i ":${1})" | sed -e 's/Delayed.*$//'`
stockadvise="${stockname} - delayed quote."
declare -a STOCKINFO
STOCKINFO=(` lynx -dump http://finance.yahoo.com/q?s=${1} | egrep -i "Last Trade:|Change:|52wk Range:"`)
stockdata=`echo ${STOCKINFO[@]}`
if ${#stockname} != 0 ;then
echo "${stockadvise}"
echo "${stockdata}"
else
stockname2=${1}
lookupsymbol=`lynx -dump -nolist http://finance.yahoo.com/lookup?s="${1}" | grep -A 1 -m 1 "Portfolio" | grep -v "Portfolio" | sed 's/\(.*\)Add/\1 /'`
if ${#lookupsymbol} != 0 ;then
echo "${lookupsymbol}"
else
echo "Sorry $USER, I can not find ${1}."
fi
fi
}

#Translate a Word - USAGE: translate house spanish # See dictionary.com for available languages (there are many).
translate ()
{
TRANSLATED=`lynx -dump "http://dictionary.reference.com/browse/${1}" | grep -i -m 1 -w "${2}:" | sed 's/^[ \t]*//;s/[ \t]*$//'`
if ${#TRANSLATED} != 0 ;then
echo "\"${1}\" in ${TRANSLATED}"
else
echo "Sorry, I can not translate \"${1}\" to ${2}"
fi
}

# Define a word - USAGE: define dog
define ()
{
lynx -dump "http://www.google.com/search?hl=en&q=define: ${1}&btnG=Google Search" | grep -m 3 -w "*" | sed 's/;/ -/g' | cut -d- -f1 > /tmp/templookup.txt
if -s /tmp/templookup.txt ;then
until ! read response
do
echo "${response}"
done < /tmp/templookup.txt
else
echo "Sorry $USER, I can't find the term \"${1} \""
fi
rm -f /tmp/templookup.txt
}



Labels:

Collateral
Comment List
Anonymous
Related Discussions
Recommended