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

Re: Shell scripting with zsh with unknown path



On 2011-06-27 10:56:35 -0400, TJ Luoma wrote:
> The problem is that I don't always know where zsh will be installed. It
> could be /usr/bin/zsh or /usr/local/bin/zsh or /bin/zsh.
> 
> I have seen perl scripts which have used
> 
>     #!/usr/bin/env perl
> 
> but that did not seem to work for zsh.

I use

  #!/usr/bin/env zsh

most of the time, and no problems with that. The only limitation is
that one cannot pass flags, such as -f. In such a case, one needs
something like:

#!/bin/sh

[ -n "$ZSH_VERSION" ] || exec zsh -f -- "$0" ${1+"$@"}

Now, for Emacs users, a consequence is that Emacs no longer sees it
as a zsh script. I have to put

# local variables:
# mode: sh
# eval: (sh-set-shell "zsh")
# end:

in the script. And in the .emacs:

(add-to-list 'safe-local-eval-forms '(sh-set-shell "zsh"))

If you don't have this, Emacs can add something similar for you
in your .emacs (you will have to confirm, as such eval forms can
be insecure).

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)



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