[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: help with combining expressions in an if statement
From: |
Chris F.A. Johnson |
Subject: |
Re: help with combining expressions in an if statement |
Date: |
Sat, 1 Jan 2005 15:07:58 -0500 (EST) |
On Sat, 1 Jan 2005, Jim wrote:
Hi,
I am new to bash and am looking for some help. Specifically, I would like to
ensure the user supplies two arguments to the shell script - month and year.
How should I combine multiple expressions in an if statement?
So far I have the following script :
month=$1
year=$2
if [ -z$month -o -z$year ]; then
echo "Usage: $0 month year";
echo "example: date.sh 01 2005";
exit 1
fi
In other words I want to say if A is true OR B is true then echo output.
The number of arguments is in the variable $#, so you can check
that:
[ $# -ne 2 ] && {
echo "Usage: $0 month year"
echo "example: date.sh 01 2005"
}
Or you can test each variable:
[ -n "$1" ] && [ -n "$2" ] || {
echo "Usage: $0 month year"
echo "example: date.sh 01 2005"
}
--
Chris F.A. Johnson
http://cfaj.freeshell.org
=================================================================
Everything in moderation -- including moderation