[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: syntax error with lone > or < as string in [ ] tests with -a or -o o
From: |
Greg Wooledge |
Subject: |
Re: syntax error with lone > or < as string in [ ] tests with -a or -o operators |
Date: |
Sun, 14 Apr 2024 09:27:58 -0400 |
On Sun, Apr 14, 2024 at 11:16:27AM +0200, Emanuel Attila Czirai wrote:
> $ [ -n ">" -a -n "something" ] || echo hmm
> bash: [: syntax error: `-n' unexpected
> hmm
Don't do this. You're in the land of unspecified behavior here.
Use multiple test or [ commands instead, or use bash's [[ command.
[ -n ">" ] && [ -n "something" ]
[[ -n ">" && -n "something" ]]
> Note, the issue is present also in (current latest) FreeBSD's '/bin/sh' and
> 'bash' and `/bin/[`.
That's because they all try to implement the POSIX rules.
> But doesn't happen on Gentoo's /usr/bin/[ which is from
> sys-apps/coreutils-9.5::gentoo
Who knows what that one does.