[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is this a bug in [[ -f ]]?
From: |
Suvayu Ali |
Subject: |
Re: Is this a bug in [[ -f ]]? |
Date: |
Fri, 19 Aug 2011 14:45:05 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Hi everyone,
Greg Wooledge <wooledg <at> eeg.ccf.org> writes:
>
> On Thu, Aug 18, 2011 at 12:35:37PM -0400, Steven W. Orr wrote:
> > lrwxrwxrwx. 1 sorr fc 5 Aug 18 08:48 err -> errio
> > -rw-rw-r--. 1 sorr fc 3816 Aug 18 08:48 errio
>
> > *836 > [[ -f err ]]
> > 837 > echo $? # BAD answer
> > 0
>
> Sounds like you want this:
>
> http://mywiki.wooledge.org/BashFAQ/097 - How do I determine whether a
> symlink is dangling (broken)?
>
>
I follow the reasoning above, but I still have a related but not exactly the
same issue.
I am trying to test if a file exists and then source it. My problem is
the test succeeds even if the variable is empty! If I pass no argument
at all, it still succeeds. To give you an example:
$ unset bla
$ [ -f $bla ] && echo yes
yes
$ [ -f ] && echo yes
yes
I don't understand this behaviour. I would have expected this to fail since $bla
is blank. Can someone please explain?
Thanks a lot.
PS: I am not subscribed to the list, could you please cc me to any responses.
--
Suvayu
Open source is the future. It sets us free.