From unknown Fri Aug 15 17:21:16 2025 X-Loop: help-debbugs@gnu.org Subject: bug#10390: Bug with Test Command Resent-From: "Mathi.C" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 28 Dec 2011 09:00:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 10390 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 10390@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.132506279820968 (code B ref -1); Wed, 28 Dec 2011 09:00:03 +0000 Received: (at submit) by debbugs.gnu.org; 28 Dec 2011 08:59:58 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RfpMc-0005S5-6V for submit@debbugs.gnu.org; Wed, 28 Dec 2011 03:59:58 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RfmnY-0001nm-KE for submit@debbugs.gnu.org; Wed, 28 Dec 2011 01:15:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rfmkv-0003PZ-5M for submit@debbugs.gnu.org; Wed, 28 Dec 2011 01:12:53 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_LOW,T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([140.186.70.17]:59842) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rfmku-0003PS-Qf for submit@debbugs.gnu.org; Wed, 28 Dec 2011 01:12:52 -0500 Received: from eggs.gnu.org ([140.186.70.92]:41413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rfmkt-0004Zu-PU for bug-coreutils@gnu.org; Wed, 28 Dec 2011 01:12:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rfmks-0003P3-N5 for bug-coreutils@gnu.org; Wed, 28 Dec 2011 01:12:51 -0500 Received: from mail-vx0-f169.google.com ([209.85.220.169]:42751) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rfmks-0003Or-Kn for bug-coreutils@gnu.org; Wed, 28 Dec 2011 01:12:50 -0500 Received: by vcge1 with SMTP id e1so10221460vcg.0 for ; Tue, 27 Dec 2011 22:12:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=yh3D8BkLWHMmKfhlzR+/iY/WDFUA/y1nxo8j85N5os4=; b=TzuGGgH5CT3LoRdzsuC7ymG8u7Jkxki8PEFpbT5f4aHioTkL7jrRz1VD9pG2gAiIZw k1wAC0V3Qvhjj+xGNKyzpvilC9McjvNrYcexurgMEuKA5KEanaJQilPbD4ZNkoVAi0c3 BVnkNgSUqqprEfYPO9habXniKvU5Z5zrBfwuc= MIME-Version: 1.0 Received: by 10.52.89.34 with SMTP id bl2mr14597601vdb.116.1325052769607; Tue, 27 Dec 2011 22:12:49 -0800 (PST) Received: by 10.220.181.71 with HTTP; Tue, 27 Dec 2011 22:12:49 -0800 (PST) Date: Wed, 28 Dec 2011 00:12:49 -0600 Message-ID: From: "Mathi.C" Content-Type: multipart/alternative; boundary=20cf307cfce6a41ee404b520e3c9 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -5.9 (-----) X-Mailman-Approved-At: Wed, 28 Dec 2011 03:59:55 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) --20cf307cfce6a41ee404b520e3c9 Content-Type: text/plain; charset=ISO-8859-1 Hi, I have come across a scenario where test command resulted wrong result than expected. Please follow the below steps to simulate the scenario. 1. Define a variable to blank/null export a= 2. Test the parameter with test command on file exists test -f $a 3. Echo the result of the last executed command echo $? Result we get is "0" -success, whereas the test command (step 2) should error with parameter expected after " test -f". -- Regards, Mathi.C --20cf307cfce6a41ee404b520e3c9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

I have come across a scenario where test command res= ulted wrong result than expected.

Please follow th= e below steps to simulate the scenario.
1. Define a variable to b= lank/null
=A0 =A0 =A0export a=3D
2. Test the parameter with test comma= nd on file exists
=A0 =A0 =A0test -f $a
3. Echo the res= ult of the last executed command=A0
=A0 =A0 echo $?
Result we get is "0" -success, whereas the test comma= nd (step 2) should error with parameter expected after " test -f"= .

--
Regards,
Mathi.C
--20cf307cfce6a41ee404b520e3c9-- From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 28 08:31:01 2011 Received: (at control) by debbugs.gnu.org; 28 Dec 2011 13:31:01 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Rftar-0005Uy-L6 for submit@debbugs.gnu.org; Wed, 28 Dec 2011 08:31:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Rftam-0005Ud-EJ; Wed, 28 Dec 2011 08:30:54 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pBSDS71D014946 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Dec 2011 08:28:07 -0500 Received: from [10.3.113.42] (ovpn-113-42.phx2.redhat.com [10.3.113.42]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pBSDS6e4004401; Wed, 28 Dec 2011 08:28:06 -0500 Message-ID: <4EFB1966.40702@redhat.com> Date: Wed, 28 Dec 2011 06:28:06 -0700 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0 MIME-Version: 1.0 To: "Mathi.C" Subject: Re: bug#10390: Bug with Test Command References: In-Reply-To: X-Enigmail-Version: 1.3.4 OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigFFA629E9A28130E90F62A32B" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Spam-Score: -10.3 (----------) X-Debbugs-Envelope-To: control Cc: 10390-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -10.3 (----------) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigFFA629E9A28130E90F62A32B Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable tag 10390 notabug thanks On 12/27/2011 11:12 PM, Mathi.C wrote: > Hi, >=20 > I have come across a scenario where test command resulted wrong result = than > expected. >=20 > Please follow the below steps to simulate the scenario. > 1. Define a variable to blank/null > export a=3D > 2. Test the parameter with test command on file exists > test -f $a There's your problem. You failed to properly quote things. Per shell expansion rules, unquoted $a is elided, rather than an empty argument, which means you passed test exactly one argument ("-f"), and since that one argument is not empty, it is always true. If you want to cope with an explicit empty string, you must use quoting: test -f "$a" > 3. Echo the result of the last executed command > echo $? As this behavior matches POSIX requirements on test, there is nothing to fix here. Also, be aware that you were probably testing your shell's built-in test, rather than coreutils' test (running the latter usually requires that you do things like 'env test' or '/usr/bin/test' to bypass shell built-ins). --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigFFA629E9A28130E90F62A32B Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJO+xlmAAoJEKeha0olJ0NqtZMH/jfSvXems+faD59r1Hx61HlZ Zkr/+jM6dO+vuHJrAKvRL1we5zxTLLQtLWPfTQzjfbxxpcIV0cBK7F8y/KExtz02 +mZuFtAK9a1NK2BI/7hAN0Xz+1sfTmC2Gd4qU7OXcqT1CygCraI8lNsA9NfqQh+M BYhQ9Uwy7d6wcmMNBJIkR3x8vDpCxeSQPtH7pgl39WfgMOTyFdl0Ogt5AOPCsq5H q6BkiovLYKCW6dYDswmltBaDuA2XfIobO/dOaP0bGabkEI8GqLNeSHIfS+lCi40J YJgvpZr6svtzIrrqE9pv9Qjv32F2PhZLZuHhFNJJ//mpK6I57EN+IlA6x2skl54= =w9HS -----END PGP SIGNATURE----- --------------enigFFA629E9A28130E90F62A32B-- From unknown Fri Aug 15 17:21:16 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: "Mathi.C" Subject: bug#10390: closed (Re: bug#10390: Bug with Test Command) Message-ID: References: <4EFB1966.40702@redhat.com> X-Gnu-PR-Message: they-closed 10390 X-Gnu-PR-Package: coreutils X-Gnu-PR-Keywords: notabug Reply-To: 10390@debbugs.gnu.org Date: Wed, 28 Dec 2011 13:31:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1325079062-21160-1" This is a multi-part message in MIME format... ------------=_1325079062-21160-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #10390: Bug with Test Command which was filed against the coreutils package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 10390@debbugs.gnu.org. --=20 10390: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D10390 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1325079062-21160-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 10390-done) by debbugs.gnu.org; 28 Dec 2011 13:30:55 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Rftap-0005Uo-F6 for submit@debbugs.gnu.org; Wed, 28 Dec 2011 08:30:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Rftam-0005Ud-EJ; Wed, 28 Dec 2011 08:30:54 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pBSDS71D014946 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Dec 2011 08:28:07 -0500 Received: from [10.3.113.42] (ovpn-113-42.phx2.redhat.com [10.3.113.42]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pBSDS6e4004401; Wed, 28 Dec 2011 08:28:06 -0500 Message-ID: <4EFB1966.40702@redhat.com> Date: Wed, 28 Dec 2011 06:28:06 -0700 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0 MIME-Version: 1.0 To: "Mathi.C" Subject: Re: bug#10390: Bug with Test Command References: In-Reply-To: X-Enigmail-Version: 1.3.4 OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigFFA629E9A28130E90F62A32B" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Spam-Score: -10.3 (----------) X-Debbugs-Envelope-To: 10390-done Cc: 10390-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -10.3 (----------) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigFFA629E9A28130E90F62A32B Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable tag 10390 notabug thanks On 12/27/2011 11:12 PM, Mathi.C wrote: > Hi, >=20 > I have come across a scenario where test command resulted wrong result = than > expected. >=20 > Please follow the below steps to simulate the scenario. > 1. Define a variable to blank/null > export a=3D > 2. Test the parameter with test command on file exists > test -f $a There's your problem. You failed to properly quote things. Per shell expansion rules, unquoted $a is elided, rather than an empty argument, which means you passed test exactly one argument ("-f"), and since that one argument is not empty, it is always true. If you want to cope with an explicit empty string, you must use quoting: test -f "$a" > 3. Echo the result of the last executed command > echo $? As this behavior matches POSIX requirements on test, there is nothing to fix here. Also, be aware that you were probably testing your shell's built-in test, rather than coreutils' test (running the latter usually requires that you do things like 'env test' or '/usr/bin/test' to bypass shell built-ins). --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigFFA629E9A28130E90F62A32B Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJO+xlmAAoJEKeha0olJ0NqtZMH/jfSvXems+faD59r1Hx61HlZ Zkr/+jM6dO+vuHJrAKvRL1we5zxTLLQtLWPfTQzjfbxxpcIV0cBK7F8y/KExtz02 +mZuFtAK9a1NK2BI/7hAN0Xz+1sfTmC2Gd4qU7OXcqT1CygCraI8lNsA9NfqQh+M BYhQ9Uwy7d6wcmMNBJIkR3x8vDpCxeSQPtH7pgl39WfgMOTyFdl0Ogt5AOPCsq5H q6BkiovLYKCW6dYDswmltBaDuA2XfIobO/dOaP0bGabkEI8GqLNeSHIfS+lCi40J YJgvpZr6svtzIrrqE9pv9Qjv32F2PhZLZuHhFNJJ//mpK6I57EN+IlA6x2skl54= =w9HS -----END PGP SIGNATURE----- --------------enigFFA629E9A28130E90F62A32B-- ------------=_1325079062-21160-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 28 Dec 2011 08:59:58 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RfpMc-0005S5-6V for submit@debbugs.gnu.org; Wed, 28 Dec 2011 03:59:58 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RfmnY-0001nm-KE for submit@debbugs.gnu.org; Wed, 28 Dec 2011 01:15:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rfmkv-0003PZ-5M for submit@debbugs.gnu.org; Wed, 28 Dec 2011 01:12:53 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_LOW,T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([140.186.70.17]:59842) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rfmku-0003PS-Qf for submit@debbugs.gnu.org; Wed, 28 Dec 2011 01:12:52 -0500 Received: from eggs.gnu.org ([140.186.70.92]:41413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rfmkt-0004Zu-PU for bug-coreutils@gnu.org; Wed, 28 Dec 2011 01:12:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rfmks-0003P3-N5 for bug-coreutils@gnu.org; Wed, 28 Dec 2011 01:12:51 -0500 Received: from mail-vx0-f169.google.com ([209.85.220.169]:42751) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rfmks-0003Or-Kn for bug-coreutils@gnu.org; Wed, 28 Dec 2011 01:12:50 -0500 Received: by vcge1 with SMTP id e1so10221460vcg.0 for ; Tue, 27 Dec 2011 22:12:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=yh3D8BkLWHMmKfhlzR+/iY/WDFUA/y1nxo8j85N5os4=; b=TzuGGgH5CT3LoRdzsuC7ymG8u7Jkxki8PEFpbT5f4aHioTkL7jrRz1VD9pG2gAiIZw k1wAC0V3Qvhjj+xGNKyzpvilC9McjvNrYcexurgMEuKA5KEanaJQilPbD4ZNkoVAi0c3 BVnkNgSUqqprEfYPO9habXniKvU5Z5zrBfwuc= MIME-Version: 1.0 Received: by 10.52.89.34 with SMTP id bl2mr14597601vdb.116.1325052769607; Tue, 27 Dec 2011 22:12:49 -0800 (PST) Received: by 10.220.181.71 with HTTP; Tue, 27 Dec 2011 22:12:49 -0800 (PST) Date: Wed, 28 Dec 2011 00:12:49 -0600 Message-ID: Subject: Bug with Test Command From: "Mathi.C" To: bug-coreutils@gnu.org Content-Type: multipart/alternative; boundary=20cf307cfce6a41ee404b520e3c9 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -5.9 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 28 Dec 2011 03:59:55 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) --20cf307cfce6a41ee404b520e3c9 Content-Type: text/plain; charset=ISO-8859-1 Hi, I have come across a scenario where test command resulted wrong result than expected. Please follow the below steps to simulate the scenario. 1. Define a variable to blank/null export a= 2. Test the parameter with test command on file exists test -f $a 3. Echo the result of the last executed command echo $? Result we get is "0" -success, whereas the test command (step 2) should error with parameter expected after " test -f". -- Regards, Mathi.C --20cf307cfce6a41ee404b520e3c9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

I have come across a scenario where test command res= ulted wrong result than expected.

Please follow th= e below steps to simulate the scenario.
1. Define a variable to b= lank/null
=A0 =A0 =A0export a=3D
2. Test the parameter with test comma= nd on file exists
=A0 =A0 =A0test -f $a
3. Echo the res= ult of the last executed command=A0
=A0 =A0 echo $?
Result we get is "0" -success, whereas the test comma= nd (step 2) should error with parameter expected after " test -f"= .

--
Regards,
Mathi.C
--20cf307cfce6a41ee404b520e3c9-- ------------=_1325079062-21160-1--