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. > > > > 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? > > /usr/bin/env is not as portable as one might think (see > http://www.in-ulm.de/~mascheck/various/shebang/#env) > > When I read this I was thinking about it a bit and came to this: > > ------------------------------------------------ > #!/bin/sh > > if test -z "$ZSH_VERSION" > then > exec zsh <"$0" > fi > > print "I'm in zsh now!" > ------------------------------------------------ > > 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 ,<'. > > > 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 necessary everything should be find. /bin/sh needs to be a bourne compatible shell and therefore must understand "exec" and "<"-redirection.
Attachment:
signature.asc
Description: This is a digitally signed message part.