From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1M2UUn-0003U9-KL for garchives@archives.gentoo.org; Fri, 08 May 2009 18:08:29 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6C3E1E0511; Fri, 8 May 2009 18:08:28 +0000 (UTC) Received: from mail.fraggod.net (unknown [91.191.238.58]) by pigeon.gentoo.org (Postfix) with ESMTP id 22F27E0511 for ; Fri, 8 May 2009 18:08:28 +0000 (UTC) Received: from coercion (coercion.core [IPv6:2001:470:1f0b:11de::13]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail.fraggod.net (Postfix) with ESMTPSA id D8994FF081 for ; Sat, 9 May 2009 00:08:20 +0600 (YEKST) Date: Sat, 9 May 2009 00:05:07 +0600 From: Mike Kazantsev To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] 'if echo hello' in .bashrc Message-ID: <20090509000507.489eab62@coercion> In-Reply-To: <200905081610.20300.alan.mckinnon@gmail.com> References: <742F0C43-196E-465B-9991-3DFF1C655803@stellar.eclipse.co.uk> <20090508200114.5edbc580@coercion> <200905081610.20300.alan.mckinnon@gmail.com> X-Mailer: Claws Mail 3.7.1 (GTK+ 2.16.1; i686-pc-linux-gnu) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/gFzbkgb9/1JStqmIYvMGGsp"; protocol="application/pgp-signature" X-Archives-Salt: f5e4d230-7cdb-40a5-b602-64bf6956eb91 X-Archives-Hash: 4629bf449c324d9ca8e65d47c78a4f12 --Sig_/gFzbkgb9/1JStqmIYvMGGsp Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Fri, 8 May 2009 16:10:20 +0200 Alan McKinnon wrote: > On Friday 08 May 2009 16:01:14 Mike Kazantsev wrote: > > > Some greps (like BSD one) might not support '--color' option, so "echo > > hello|grep --color=3Dauto l" will return error code, skipping if clause, > > and won't break grep operation by adding an unsupported option. >=20 > except that STDERR is combined with STDOUT and sent to /dev/null so the s= cript=20 > will never get it, the if is always true and the entire check is redundan= t.=20 > Better would be >=20 > if echo hello|grep --color=3Dauto l >/dev/null ; then As many ppl just pointed out, you mistake "output check" done by "[" or "test" commands with shell built-in "if" statement operation, which looks only to a given command exit code, doesn't bothering with any output. "if [ $A ]" is equivalent to "if test $A" (where "test" is "/usr/bin/test"), except that modern shells implement test command as a built-in. For the rest of them, there's actually "/usr/bin/\[" symlink, which should exist on your system as well. So what happens is "test $A", silently returning it's exit code to "if". And of course, you can use any command instead of "test". For example there's also "/bin/true" and "/bin/false", so idiomatical "if true" and "if false" would actually work as expected ;) --=20 Mike Kazantsev // fraggod.net --Sig_/gFzbkgb9/1JStqmIYvMGGsp Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.11 (GNU/Linux) iEYEARECAAYFAkoEdGMACgkQASbOZpzyXnGlJgCeJrWO/6GBYeLEPAszsJOVpA+B 5JMAoJtdzrgz4usQvUyZEIJqdWXHeMBc =OnIB -----END PGP SIGNATURE----- --Sig_/gFzbkgb9/1JStqmIYvMGGsp--