Bug 299121 - "[ -n ${emptyvariable} ]" returns true
"[ -n ${emptyvariable} ]" returns true
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: coreutils (Show other bugs)
rawhide
All Linux
low Severity low
: ---
: ---
Assigned To: Pete Graner
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2007-09-20 15:42 EDT by Jonathan Kamens
Modified: 2007-11-30 17:12 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2007-09-20 20:15:02 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jonathan Kamens 2007-09-20 15:42:01 EDT
foo=
/usr/bin/[ -n $[foo} ] && echo true

Prints "true".

Either the command should produce an error, since after expansion the ${foo} 
drops out and the ] gets interpreted as the argument to -n, which means that 
the command is missing a terminating ], or if you want to be forgiving and say 
that the command can assume that there was a variable that got expanded out of 
existence, then the command should return a non-zero exit status, since that 
variable was empty.
Comment 1 Jonathan Kamens 2007-09-20 20:15:02 EDT
Says Paul Jarc on bug-bash:

"No, the final ] is always taken to be the match for [.  Anything in
between has to be parsed consistently with that.  In this case, it
means that the test expression includes only one argument, "-n".
Since there is only one, it is taken to be an operand, even if it
happens to have the same spelling as an operator.  The operand is
tested for being nonempty, which "-n" is, so the result here is true."

Note You need to log in before you can comment on or make changes to this bug.