Bug 845929

Summary: test -n always returns 0 if evaluating variable
Product: Red Hat Enterprise Linux 6 Reporter: Martin Kyral <mkyral>
Component: coreutilsAssignee: Ondrej Vasik <ovasik>
Status: CLOSED NOTABUG QA Contact: qe-baseos-daemons
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.2CC: kdudka, maxamillion, meyering, ovasik, p, twaugh
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 845925 Environment:
Last Closed: 2012-08-06 07:30:28 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 845925    
Bug Blocks:    

Description Martin Kyral 2012-08-06 07:19:53 UTC
+++ This bug was initially created as a clone of Bug #845925 +++

Description of problem:
According to the man page, "test -n STRING" returns true (0) if the STRING's length is non-zero and that it equivalent to "test STRING" (and contrary to "test -z STRING").

Version-Release number of selected component (if applicable):
coreutils-8.4-19.el6.x86_64

How reproducible:
Always


Steps to Reproduce:
1. VAR=''
2. test -n $VAR ; echo $?
3. test $VAR ; echo $?

  
Actual results:
In step 2, the output is 0 (true in shell semantics).


Expected results:
In step 2, the output is 1 (false in shell semantics).

Additional info:
"test -n $VAR" returns 0 on both empty and non-empty string $VAR value. "test $VAR" and "test -z $VAR" give the expected values, ie. 0,1 on non-empty and 1,0 on empty $VAR values. Also, "test -n" gives correct output if a direct value is given.

Comment 1 Kamil Dudka 2012-08-06 07:30:28 UTC
see bug #845925 comment #2