[Top][All Lists]

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

Re: test -f with no args is true

From: Bob Proulx
Subject: Re: test -f with no args is true
Date: Sat, 15 Apr 2006 12:52:07 -0600
User-agent: Mutt/1.5.9i

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

  if [ "$variable" ]; then
    echo variable contains data

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:


The pertinent lines are:

  0 arguments:
      Exit false (1).
  1 argument:
      Exit true (0) if $1 is not null; otherwise, exit false.
  2 arguments: ...


reply via email to

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