Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Apr 2002 00:06:21 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Glenn Johnson <gjohnson@srrc.ars.usda.gov>
Cc:        questions@freebsd.org
Subject:   Re: why does this test condition not work?
Message-ID:  <20020403210621.GH848@hades.hell.gr>
In-Reply-To: <20020403172111.GA88600@node1.cluster.srrc.usda.gov>
References:  <20020403172111.GA88600@node1.cluster.srrc.usda.gov>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2002-04-03 11:21, Glenn Johnson wrote:
> I am writing a script am am trying to prompt for input and make sure all
> of the values are entered. I have the following test condition in my
> script but when I run it I get:
>
> [: -z: unexpected operator

> while [ -z $tor1a -o -z $tor1b -o -z $tor1c -o -z $tor1d ]
> do
>         read -p "Enter the atom numbers of the first torsion: " tor1a
> 	tor1b tor1c tor1d
> done

Because at first all of your variables are unset, and the test within
brackets is expanded by sh to:

	[ -z -o -z -o -z -o -z ]

The first -o is consumed by the previous -z, and then test(1) moves on
to check the rest of it's arguments and finds a -z (the second -z)
where it would expect -or or -and.

Try this instead:

while [ -z "$tor1a" -o -z "$tor1b" -o -z "$tor1c" -o -z "$tor1c" ]
do
	echo -n "Enter the atom numbers of the first torsion: "
	read tor1a to1b tor1c tor1d
done

Giorgos Keramidas                       FreeBSD Documentation Project
keramida@{freebsd.org,ceid.upatras.gr}  http://www.FreeBSD.org/docproj/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020403210621.GH848>