From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1069 invoked by alias); 1 Feb 2011 20:21:15 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28689 Received: (qmail 16460 invoked from network); 1 Feb 2011 20:21:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.161.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:reply-to:to:subject:date:user-agent :references:in-reply-to:mime-version:content-type :content-transfer-encoding:message-id; bh=tn7ZE94UdHLQ1a9XVeNB7D2wcEOEnb2GyDfWlKsb5B4=; b=tsY94wTqzn7iCj69j4c342mvHaA7ls3f0d9UFB8y9LkwlJ1gaZYXWTf5XyM6VeqT0R i7dYFQ+og2378lnOrRNzh36VncQckMEaazORYuM7LYbmGkwtn0JFmOs4nkQtZYSLZFDm YOFP83E8NNuom+mu33lzOiMREA/R2g+n/0W98= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; b=boVBV0IRZzpuWSYW07htmtvWnCikwu2cCkBcLcLUt3E1VHPm/kcK4v1jdWd1N27A3K CgMBFQou8Wcx8bjhyTjny2pKcQJmMfhNIpvAig0b3lBP09pQCF9RVrGcCw7UZFkzPcj9 N+Iy1EKkbWajjtgEhSQGst8ajAGffP237Wwd0= From: ZyX Reply-To: zyx.vim@gmail.com To: zsh-workers@zsh.org Subject: Re: Check existence of a program Date: Tue, 1 Feb 2011 23:21:02 +0300 User-Agent: KMail/1.13.5 (Linux/2.6.36-zen1; KDE/4.5.5; x86_64; ; ) References: <4D4850F7.6060205@gmail.com> <201102012212.10494@-zyx> In-Reply-To: <201102012212.10494@-zyx> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart3738568.ffRhNXkQVx"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201102012321.03053@-zyx> --nextPart3738568.ffRhNXkQVx Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Reply to message =C2=ABRe: Check existence of a program=C2=BB,=20 sent 22:12:09 01 February 2011, Tuesday by ZyX: Sorry, I should have read your question more correctly (and test $(cmd) var= iant=20 better). $(cmd) actually propagates exit code, so the reason is overriding = of=20 $path as others have mentioned. Original message: > Reply to message =C2=ABCheck existence of a program=C2=BB, > sent 21:29:11 01 February 2011, Tuesday > by Anonymous bin Ich: >=20 > prog=3Dexiftime > path=3D=3D$prog > if [[ $? -ne 0 ]] ; then > prog=3Didentify > path=3D=3D$prog > endif >=20 > It works because zsh takes first =3D as assignment operator and expands > second `=3D$prog' construct into a full path. If `=3D$prog' expansion fai= ls, > it throws an exception, exception prevents variable from being set and > thus last expression fails what is indicated in $?. >=20 > If you use $(cmd) construct, then though `cmd' fails, $(cmd) that does not > care about exit code just expands into output of `cmd', so last expression > (which is variable assignment, NOT `cmd') does not fail. Also note that > `=3D$prog' does not produce new fork. >=20 > Original message: > > Hello! > >=20 > > I am having trouble checking for existence of a program. > >=20 > > This works: > >=20 > > % cat working.zsh > > #!/bin/zsh > > set -x > > prog=3D"identify" > > path=3D$(which ${prog}) > > % > > % ./working.zsh > > +./working.zsh:3> prog=3Didentify > > +./working.zsh:4> path=3D+./working.zsh:4> which identify > > +./working.zsh:4> path=3D/usr/bin/identify > > % > >=20 > > But this doesn't: > >=20 > > % cat notworking.zsh > > #!/bin/zsh > > set -x > > prog=3D"exiftime" > > path=3D$(which ${prog}) > > if [[ ${?} -ne 0 ]]; then > >=20 > > prog=3D"identify" > > path=3D$(which ${prog}) > >=20 > > fi > > % > > % ./notworking.zsh > > +./notworking.zsh:3> prog=3Dexiftime > > +./notworking.zsh:4> path=3D+./notworking.zsh:4> which exiftime > > +./notworking.zsh:4> path=3D'exiftime not found' > > +./notworking.zsh:5> [[ 1 -ne 0 ]] > > +./notworking.zsh:6> prog=3Didentify > > +./notworking.zsh:7> path=3D+./notworking.zsh:7> which identify > > +./notworking.zsh:7> path=3D'identify not found' > > % > >=20 > > Any idea? --nextPart3738568.ffRhNXkQVx Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) iEYEABECAAYFAk1Iay8ACgkQkOgHluiXxU/rRACfR8mtTTwL8LSGMK8jZx/s35su ArUAn0YDw5tVzlj6TtJVRD9pmJ6keYED =X/zx -----END PGP SIGNATURE----- --nextPart3738568.ffRhNXkQVx--