« Facebook | Main | smpatch access to remote servers »

Shell - Test for argument

I always forget this and spend ages finding out how to do it. How to test for an argument passed from the command line to a shell script, and not get "argument expected" error:

if [ -z "$1" ]; then
echo argument expected
exit 1
fi

The secret is the quotes around the $1.

TrackBack

TrackBack URL for this entry:
http://www.numbersix.net/cgi-bin/mt/mt-tb.cgi/23

About

This page contains a single entry from the blog

The previous post in this blog was Facebook.

The next post in this blog is smpatch access to remote servers.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33