|
From: | Maciek Olczak |
Subject: | Test-ing file types |
Date: | Wed, 23 Jul 2003 12:11:28 +1000 |
In rather unfortunate situation I found that /usr/bin/test gives false positive results when asked to test file types when no argument (null value) is supplied. Eg:
# if [ -d ${file} ]; then echo success; fi
success
#
# echo ~${file}~
~~
# [ -d ${file} ]; echo $?
0
#
# /usr/bin/test --version
test (GNU coreutils) 4.5.3
Written by FIXME: ksb and mjb.
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
#
There may be some explanation for such behaviour to be reasonable, (see http://mail.gnu.org/archive/html/bug-sh-utils/2002-05/msg00018.html). If there is not, I guess test could be changed to follow the same logic as with test in-built into bash, for example. There I get more logical results:
# if [[ -d ${file} ]]; then echo success; fi
#
# [[ -d ${file} ]]; echo $?
1
#
Kind regards
Maciek Olczak
Tramada Systems Pty. Ltd.
[Prev in Thread] | Current Thread | [Next in Thread] |