zsh-users
 help / color / mirror / code / Atom feed
* Shell scripting with zsh with unknown path
@ 2011-06-27 14:56 TJ Luoma
  2011-06-27 16:51 ` Bart Schaefer
  2011-06-28  0:44 ` Vincent Lefevre
  0 siblings, 2 replies; 3+ messages in thread
From: TJ Luoma @ 2011-06-27 14:56 UTC (permalink / raw)
  To: Zsh Users


I have always written my shell scripts in #!/bin/sh or 
#!/bin/bash but there are times when I find that I would really 
prefer to use zsh.

Ideally I'd like to be able to write all of my scripts in zsh so 
I don't have to keep two syntax/feature sets in my head.

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.

TjL




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Shell scripting with zsh with unknown path
  2011-06-27 14:56 Shell scripting with zsh with unknown path TJ Luoma
@ 2011-06-27 16:51 ` Bart Schaefer
  2011-06-28  0:44 ` Vincent Lefevre
  1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2011-06-27 16:51 UTC (permalink / raw)
  To: Zsh Users

On Jun 27, 10:56am, TJ Luoma wrote:
} Subject: Shell scripting with zsh with unknown path
}
} 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.

There are several options here.  Among them:

(1) Write your zsh scripts so they can be autoloaded as shell functions,
and place them in directories in your $fpath.  This doesn't work if you
want to run your zsh scripts from other shells.

(2) Use a program to fix the #! line of all your scripts whenever you
install them on a new host.  E.g.

    perl -pi.orig -e 's@^(#!)/.*?/zsh\b@$1$ENV{SHELL}@; last' ...

where "..." is some pattern that matches your script files.

} I have seen perl scripts which have used
} 
}      #!/usr/bin/env perl
} 
} but that did not seem to work for zsh.

I know others here have successfully used this, though it does cause
some complications (can't pass -f to zsh, for example).


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Shell scripting with zsh with unknown path
  2011-06-27 14:56 Shell scripting with zsh with unknown path TJ Luoma
  2011-06-27 16:51 ` Bart Schaefer
@ 2011-06-28  0:44 ` Vincent Lefevre
  1 sibling, 0 replies; 3+ messages in thread
From: Vincent Lefevre @ 2011-06-28  0:44 UTC (permalink / raw)
  To: zsh-users

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@vinc17.net> - 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)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-28  0:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-27 14:56 Shell scripting with zsh with unknown path TJ Luoma
2011-06-27 16:51 ` Bart Schaefer
2011-06-28  0:44 ` Vincent Lefevre

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).