From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29394 invoked by alias); 21 Jul 2010 08:35:45 -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: 15195 Received: (qmail 23665 invoked from network); 21 Jul 2010 08:35:40 -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,SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at m.gmane.org designates 80.91.229.12 as permitted sender) X-Injected-Via-Gmane: http://gmane.org/ To: zsh-users@zsh.org From: Thorsten Kampe Subject: Re: zsh portable script Date: Wed, 21 Jul 2010 10:34:54 +0200 Message-ID: References: <1007130241570.5546@smasher> <201007121737.21296.joke@seiken.de> <305645C3-6FF2-4D54-AC28-372D60283E07@free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: nat.scz.novell.com User-Agent: MicroPlanet-Gravity/2.9.15 * François Revol (Tue, 20 Jul 2010 16:07:32 +0200) > Le 20 juil. 2010 à 15:53, Thorsten Kampe a écrit : > > * Joke de Buhr (Mon, 12 Jul 2010 17:37:19 +0200) > >> On Monday 12 July 2010 16:46:22 Atom Smasher wrote: > >>> on freebsd, zsh installs as /usr/local/bin/zsh. on linux (and most > >>> other systems?) it installs as /usr/bin/zsh. > >>> > >>> what's the best way to make zsh script portable between linux and > >>> freebsd? > >>> > >>> i could start the script with: > >>> #!/usr/bin/env zsh > >>> > >>> or i could specify that the script be executed as: > >>> zsh script > >>> > >>> is there a better way? > >> > >> Using env doesn't solve the problem either. There is no guarantee the "env" > >> program is installed under /usr/bin/env. > > > > It does solve the problem that's why it's used in (shell) scripting[1]. > > No it does not. > BeOS never had any /usr. > Haiku doesn't either. The question was "what's the best way to make zsh script portable between linux and freebsd?" Why would the original poster care about OSs which are either dead for ten years or haven't left alpha stage yet? If you want to be generally "portable" then you wouldn't write a zsh script in the first place: "When portability is an issue: you can rely on the Bourne shell existing anywhere. Scripting languages like Perl and even the newer shells like bash and zsh are potentially unavailable" ("From Bash to Z Shell" - Oliver Kiddle, Jerry Peek and Peter Stephenson) Trying to create a script that would magically "run everywhere" is never going to work. For a "real life" description see here: "While the transition to sh and general UNIX compatibility has been a bumpy ride, it has also been a tremendous learning experience. Creating a single script that runs on all of these platforms has been very tricky indeed, mainly because I simply don't have access to most of these operating systems! Thankfully, keychain users from around the globe do, and many have provided great assistance in identifying compatibility problems and submitting patches to fix them."[1] All these compatibility changes come with a heavy price: they make the code much less readable (as described under "Shell compatibility fixes"[1]) The lesson here is: if you want a Zsh script that runs on the major Linux distributions and on FreeBSD then create one that does exactly that. Don't try to "over-engineer" to make it run everywhere if you don't have the ressources (like lots of contributors) and especially: dont't try to make it run on a platform you don't have access to (and on which the script is never supposed to run, anyway). Thorsten [1] http://www.gentoo.org/doc/en/articles/openssh-key-management-p3.xml