Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh portable script



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


Messages sorted by: Reverse Date, Date, Thread, Author