From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21307 invoked by alias); 12 Jul 2010 16:10:24 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15172 Received: (qmail 2823 invoked from network); 12 Jul 2010 16:10:18 -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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at seiken.de designates 94.23.38.107 as permitted sender) From: Joke de Buhr To: zsh-users@zsh.org Subject: Re: zsh portable script Date: Mon, 12 Jul 2010 18:10:06 +0200 User-Agent: KMail/1.13.2 (Linux/2.6.32-22-generic; KDE/4.4.2; x86_64; ; ) References: <1007130241570.5546@smasher> In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart7848632.Dc25pmtlND"; protocol="application/pgp-signature"; micalg=pgp-ripemd160 Content-Transfer-Encoding: 7bit Message-Id: <201007121810.09331.joke@seiken.de> --nextPart7848632.Dc25pmtlND Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Monday 12 July 2010 17:35:34 Sebastian Stark wrote: > Am 12.07.2010 um 16:46 schrieb Atom Smasher: > > on freebsd, zsh installs as /usr/local/bin/zsh. on linux (and most other > > systems?) it installs as /usr/bin/zsh. > >=20 > > what's the best way to make zsh script portable between linux and > > freebsd? > >=20 > > i could start the script with: > > #!/usr/bin/env zsh > >=20 > > or i could specify that the script be executed as: > > zsh script > >=20 > > is there a better way? >=20 > /usr/bin/env is not as portable as one might think (see > http://www.in-ulm.de/~mascheck/various/shebang/#env) >=20 > When I read this I was thinking about it a bit and came to this: >=20 > ------------------------------------------------ > #!/bin/sh >=20 > if test -z "$ZSH_VERSION" > then > exec zsh <"$0" > fi >=20 > print "I'm in zsh now!" > ------------------------------------------------ >=20 > Since the script is fed to /bin/sh via stdin it shouldn't be a problem if > it contains zsh-specific syntax after the exec. I never used this > construct and I'm not sure how portable it really is. Also I don't know if > one can assume that /bin/sh understands ,exec' and ,<'. >=20 >=20 > Sebastian Sorry I wrote I the version with the "<" in the first place. calling zsh this way doesn't pass invocation arguments. If that is not=20 necessary everything should be find. /bin/sh needs to be a bourne compatible shell and therefore must understand= =20 "exec" and "<"-redirection. --nextPart7848632.Dc25pmtlND Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQG7BAABAwAlBQJMOz5fHhhoa3A6Ly9wb29sLnNrcy1rZXlzZXJ2ZXJzLm5ldAAK CRCWUloJhwFWxr2PC/9CTbcVS2Q50Y54cZdqHoeYIHoq5LUhBhsx/u9nXmQurNUk PcePBRBHfCd6tlrhZkQwAYdmpfgmVIaCMGJVZOOKge4V0+cGbNb9iT+5KCWbkYL7 QVMDXeq1PNM1+ToiUXE60RdIIzu/EsW9iPfKRV4YE1XRfHKSlFBRkgO3Swlo5jcG 1zmFVCDPTmp3CQs8PmDgfVbqC4p44T4Njq70wXQDXJ6mnZxmhwbXnEifAl5/9qOT thm4t7hMIRGwOSDsqZgquKK3BRn3YPSCcxIiIfUxYdKN62HphigSKvAISsN3DG1/ 7VT1qbbb7e0nx7ewy+B0EcU5KixZ0W3boLGyrxUFjmC+89hSJtYj231sOl2M6Vml 53rWDPN4StH6Zo9WDUx6MCbevQbGamdpD5TMU80oBEgEvX+W+Cn/uLQD8AfGRe9P 8tM7MlnTdbATAJLVf4UhiGuHlGOmlbUvnrDnbqRF2ePeNKBzJNeuJoNFWvnvrDMP e+maqzL8U56r1+Uwwx4= =Dwbs -----END PGP SIGNATURE----- --nextPart7848632.Dc25pmtlND--