Date: 03 May 1997 16:20:35 +0200 From: Wolfram Schneider <wosch@apfel.de> To: Steve Howe <un_x@anchorage.net> Cc: freebsd-questions <questions@FreeBSD.ORG> Subject: Re: test -f $shvar Message-ID: <p1irafobpsc.fsf@campa.panke.de> In-Reply-To: Steve Howe's message of Sat, 3 May 1997 02:41:57 -0800 (AKDT) References: <Pine.BSF.3.95q.970503023817.7560A-100000@aak.anchorage.net>
index | next in thread | previous in thread | raw e-mail
Steve Howe <un_x@anchorage.net> writes:
> anyone notice how "test -f $shvar" always results in "true"?
This happens if the variable `shvar' is empty. This is correct because
test(1) got only one argument and assume `-f' is a non-empty string
and not the option `-f file'.
$ man test
string True if string is not the null string.
> whether the file exists or not, the test is always true?
test did not got a file.
> i don't really understand why this is! is it a bug?
The programmer must check if the variable `shvar' is
not empty. E.g.:
test -n "$shvar" -a -f "$shvar"
--
Wolfram Schneider <wosch@apfel.de> http://www.apfel.de/~wosch/
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p1irafobpsc.fsf>
