bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: test -f with no args is true


From: cbennett
Subject: Re: test -f with no args is true
Date: Sat, 15 Apr 2006 16:52:07 -0400 (EDT)
User-agent: SquirrelMail/1.4.2-1

Hmmmm.  I sat on that blasted committee.

I'll file a corrigendum or whatever it's called.  This should at
least be called out in the rationale.

No biggie.  I'll just make sure I quote all of my args.

ccb


> Charlie Bennett wrote:
>> Is this expected behavior?
>>
>> address@hidden .ssh]# [ -f  ]
>> address@hidden .ssh]# echo $?
>> 0
>
> Yes.  That is expected behavior.  With one argument the return code is
> true if the string is non-zero in length.  The case covered is this
> case:
>
>   if [ "$variable" ]; then
>     echo variable contains data
>   fi
>
> Because you can enter any data you want into variable if it were
> interpreted as a -f operator then you would get the dreaded "test:
> argument expected" message as was often seen before this rule came
> into place.  POSIX requires this behavior.  See this document:
>
>   http://www.opengroup.org/onlinepubs/009695399/utilities/test.html
>
> The pertinent lines are:
>
>   0 arguments:
>       Exit false (1).
>   1 argument:
>       Exit true (0) if $1 is not null; otherwise, exit false.
>   2 arguments: ...
>
> Bob
>
>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]