Google Site SearchFN Site Search FN Blog Login FN Blog Login
Site Navigation:

FUN WITH SHELLS: a nifty command line driven weather forecast

by Andrew Newman (CREATED: 2004-02-24)

This is the first, in what I plan to be a series, called "Fun with Shells". The point of these articles will be to not only pass around some increadibly useful simple shells, but also, hopefully encourage people to jump in and either modify these or write their own.

This contribution is a very simple bash shell that I wrote for calling up the weather forecast (thanks to What is nice about this shell and the wunderground site, is that you can call up the forecast for just about anywhere (at least from what I can tell).

Here is the script
# program myforecast
# version 1.0  
# written by Andrew V. Newman
# last modified Tue Feb 24 17:21:57 MST 2004

# shell script to bring up a weather forecast either on a
# graphical browser or in the console if the screen is not available.

# Create a default location.  This assumes you live in the US as I do.
  CITY=Los_Alamos  # use underscore to separate multi-word cities
# Sets a default URL BASE  
# Set the default graphical browser 
# I like galeon, but it may not be installed on your machine.

# ---------------------------- #
# Shouldn't have to change these
# If you use just one variable
  if [ $1 ] ; then
# If you use two variables
  if [ $2 ]; then

# If you can display a window on your terminal it will
# bring up your forecast in a graphical browser
  if [ $DISPLAY ]; then
     $GUI_BROWSER $URL 2> /dev/null
# Otherwise, it will bring it up on screen using a version
# of the website set up for mobile computers (no ads and few graphics,
# which will not be displayed anyway).
     $LYNX $URL -dump 2> /dev/null >forecast.temp
     # displays forecast as text
       more forecast.temp
     # remove temporary file
       rm forecast.temp
# exit cleanly
  exit 0

It may be easier to just download a copy (right click).

Once you have a copy on your system, all you need to do is:

  • Modify the first two variables to create your own defaults.
  • Change permissions of the file so that you can execute it:
    % chmod 755 myforecast
  • Move file to a directory in your path:
    I would suggest creating a bin directory from your home for all shells and then making certain it is included in your path. % mkdir ~/bin
    % mv myforecast ~/bin/
    If it is not already there, add the following line to ~/.cshrc if you are using a csh or tcsh shell path = ( $path ~/bin) Or, if you are using bash add the following line to ~/.bashrc PATH=$PATH:~/bin

If you look through the program, you will notice that there is a default set up for my home town. Certainly you should change to whatever you want. It is important to note here, that though gives forecasts for cities around the globe, the script is really set to work within the US.
Ok, now that you have set your defaults, give the program a shot. Try running the following commands: % myforecast
% myforecast Chicago IL
% myforecast 87544
% myforecast Tokyo

UPDATED: Check out 2004-03-02 MYRADAR: a radar companion to myforecast.

Please email me if you have any comments or suggestions!