Bug 299121

Summary: "[ -n ${emptyvariable} ]" returns true
Product: [Fedora] Fedora Reporter: Jonathan Kamens <jik>
Component: coreutilsAssignee: Pete Graner <pgraner>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: rawhideCC: twaugh
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
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: ---

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."