Last Updated: February 25, 2016
· donutdan4114

Getting weather via the command line

After reading this Pro Tip: I decided to make my own version in a way that I know how... PHP.

For this to work, you need to have PHP, and it needs to be part of your system PATH. If it isn't, just modify the php part of the script to be the path to your PHP executable.

Put this function into your .bashrc file:


 local zip=$1
 php -r '$xml = simplexml_load_file("'${zip}'"); foreach($xml->txt_forecast->forecastday as $weather){ echo "{$weather->title}: "; echo $weather->fcttext; echo PHP_EOL . PHP_EOL;}' 


Now in console, just type:

$> weather ZIP_CODE

You'll get the forcast for the next few days.