[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bash -f Test Operator - Not working as expected
From: |
Greg Wooledge |
Subject: |
Re: Bash -f Test Operator - Not working as expected |
Date: |
Tue, 2 May 2017 08:13:17 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Mon, May 01, 2017 at 11:24:44PM -0500, Eduardo Bustamante wrote:
> > For the behavior you want, you need something like:
> >
> > test ! -h "$pathname" -a -f "$pathname"
Don't use that.
test ! -h "$pathname" && test -f "$pathname"
would be safe. Your test command has 6 arguments, for which "the results
are unspecified".
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
Also, personally I prefer -L over -h, because -L is easier to remember.
But there are older systems where -h is documented but -L is not, so
you're not wrong there. (HP-UX 10.20's test(1) documents -h and not -L,
but they both work. I suppose there are actually some systems where -L
doesn't work, but I don't have access to any.)