[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
`builtin test -a foo` VS `builtin test ! -a foo`
From: |
Name withheld by request |
Subject: |
`builtin test -a foo` VS `builtin test ! -a foo` |
Date: |
Tue, 16 Jan 2007 22:50:37 +0000 (GMT) |
In article <1168097154.128051@irys.nyx.net>,
Name withheld by request <anonb6e9@nyx.nyx.net> wrote:
>In bash the built-in 'test' command can act either as "and",
>or as a test for file existence:
>
> ~ $ help test|grep -e -a
> -a FILE True if file exists.
> EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
>
>I'm pretty sure this is not a bug, but please explain why:
>
> ~ $ cd /tmp
> /tmp $ date;uname -a
> Sat Jan 6 09:09:19 CST 2007
> Linux alex 2.6.5-1.358 #1 Sat May 8 09:04:50 EDT 2004 i686 athlon i386
> GNU/Linux
> /tmp $ touch foo
> /tmp $ builtin test -a foo && echo hi
> hi
> /tmp $ builtin test ! -a foo && echo hi
> hi
> /tmp $
A bit more:
/tmp $ rm -f foo; ls foo
ls: foo: No such file or directory
/tmp $ builtin test -a foo || echo ho
ho
/tmp $ builtin test ! -a foo || echo ho
/tmp $
So
builtin test ! -a foo
is equivalent to
true
ie it's not very useful, what is it I'm missing, why is this not a bug?
--
thanks
Tom
--------------------------
/tmp $ help test|egrep -A6 'Other operators'
Other operators:
-o OPTION True if the shell option OPTION is enabled.
! EXPR True if expr is false.
EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
EXPR1 -o EXPR2 True if either expr1 OR expr2 is true.
--snip
/tmp $ touch foo;ls foo
foo
/tmp $ test -e foo;echo $?
0
/tmp $ test ! -e foo;echo $?
1
/tmp $ rm foo; ls foo
ls: foo: No such file or directory
/tmp $ test -e foo;echo $?
1
/tmp $ test ! -e foo;echo $?
0
/tmp $
- `builtin test -a foo` VS `builtin test ! -a foo`,
Name withheld by request <=