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"
}