unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Emacs script that works on all platforms
@ 2010-05-20 19:01 Johan Andersson
  2010-05-21 13:24 ` Tassilo Horn
  0 siblings, 1 reply; 6+ messages in thread
From: Johan Andersson @ 2010-05-20 19:01 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 861 bytes --]

Hey,


I have an Emacs script where the first line looks like this:
#!/usr/bin/emacs --script

However, on Mac OSX, Emacs is installed by default, but with an old version.

I have also installed Emacs via Homebrew (compiled from source) and can run
that with:
/Usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs

So, to run the script with the Homebrew version, I could change the first
line in my script to:
#!/Usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs --script

That works, but I want this script to work on both GNU/Linux and Mac OSX
(Both default and Homebrew version).

I was thinking I could use env somehow, like this:
#!/usr/bin/env emacs --script

And then make emacs an alias or function that points to the correct binary
depending on system. But it's still the default Emacs that is used.


Any ideas how I could solve this?

[-- Attachment #2: Type: text/html, Size: 1142 bytes --]

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

* Re: Emacs script that works on all platforms
       [not found] <mailman.15.1274382091.29716.help-gnu-emacs@gnu.org>
@ 2010-05-20 20:40 ` Frédéric Perrin
       [not found] ` <3c0b258e-32ae-4ab8-b936-3d304f3e4771@34g2000prs.googlegroups.com>
  1 sibling, 0 replies; 6+ messages in thread
From: Frédéric Perrin @ 2010-05-20 20:40 UTC (permalink / raw)
  To: help-gnu-emacs

Johan Andersson <johan.rejeep@gmail.com> writes:
> I have an Emacs script where the first line looks like this:
> #!/usr/bin/emacs --script
>
> However, on Mac OSX, Emacs is installed by default, but with an old
> version.
>
> I have also installed Emacs via Homebrew (compiled from source) and
> can run that with:
> /Usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs
>
> So, to run the script with the Homebrew version, I could change the
> first line in my script to:
> #!/Usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs
> --script
>
> That works, but I want this script to work on both GNU/Linux and Mac
> OSX (Both default and Homebrew version).
>
> I was thinking I could use env somehow, like this:
> #!/usr/bin/env emacs --script
>
> And then make emacs an alias or function that points to the correct
> binary depending on system. But it's still the default Emacs that is
> used.

In `/usr/bin/env emacs', env(1) will execvp(3) `emacs' ; so it won't
follow your shell aliases or functions.

Ideas :

Put ~/bin as the first thing in your $PATH, and make ~/bin/emacs a
symlink to the emacs you want to use. Then, use the `/usr/bin/env
emacs' trick.

Expand on the sesquicolon as described in [1]. Something like
(untested):

:; [ `uname` == "linux" ] && exec /usr/bin/emacs --batch -l $0 $* || exec /Usr/local/.../Emacs --batch -l $0 $*

[1] http://www.emacswiki.org/emacs/EmacsScripts

-- 
Fred


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

* Re: Emacs script that works on all platforms
  2010-05-20 19:01 Emacs script that works on all platforms Johan Andersson
@ 2010-05-21 13:24 ` Tassilo Horn
  2010-05-27 12:51   ` Johan Andersson
       [not found]   ` <mailman.0.1274964713.14889.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Tassilo Horn @ 2010-05-21 13:24 UTC (permalink / raw)
  To: help-gnu-emacs

Johan Andersson <johan.rejeep@gmail.com> writes:

Hi Johan,

> #!/usr/bin/emacs --script
>
> However, on Mac OSX, Emacs is installed by default, but with an old
> version.
>
> I have also installed Emacs via Homebrew (compiled from source) and can run
> that with:
> /Usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs
>
> [...]
>
> I was thinking I could use env somehow, like this:
> #!/usr/bin/env emacs --script
>
> And then make emacs an alias or function that points to the correct
> binary depending on system. But it's still the default Emacs that is
> used.

"env cmd" uses the cmd it finds first when checking the directories in
your $PATH.  For example I have:

--8<---------------cut here---------------start------------->8---
% echo $PATH
/home/horn/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.4.3:/usr/games/bin
--8<---------------cut here---------------end--------------->8---

Now I make a symlink to `less' that I call `emacs' inside
/home/horn/bin:

--8<---------------cut here---------------start------------->8---
% cd ~/bin
% ln -s /usr/bin/less emacs
% zsh   # start a new shell
% emacs
Missing filename ("less --help" for help)
--8<---------------cut here---------------end--------------->8---

So as you can see, when calling `emacs' it finds the emacs-symlink to
less first, cause that resides in a directory that comes before
/usr/bin in PATH.

HTH,
Tassilo




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

* Re: Emacs script that works on all platforms
       [not found] ` <3c0b258e-32ae-4ab8-b936-3d304f3e4771@34g2000prs.googlegroups.com>
@ 2010-05-22 12:31   ` Tassilo Horn
  0 siblings, 0 replies; 6+ messages in thread
From: Tassilo Horn @ 2010-05-22 12:31 UTC (permalink / raw)
  To: help-gnu-emacs

Xah Lee <xahlee@gmail.com> writes:

Hi Xah,

> from my experiences, it's best to avoid the shebang construct. Just
> call the program directly.

Yes, that's absolutely the best thing to do for scripts that should run
on many systems on different platforms. ;-)

Bye,
Tassilo


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

* Re: Emacs script that works on all platforms
  2010-05-21 13:24 ` Tassilo Horn
@ 2010-05-27 12:51   ` Johan Andersson
       [not found]   ` <mailman.0.1274964713.14889.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Johan Andersson @ 2010-05-27 12:51 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1709 bytes --]

Hey,

To bad you could not get away with an alias or function though... But it
works, thanks for the tip! :)

On Fri, May 21, 2010 at 3:24 PM, Tassilo Horn <tassilo@member.fsf.org>wrote:

> Johan Andersson <johan.rejeep@gmail.com> writes:
>
> Hi Johan,
>
> > #!/usr/bin/emacs --script
> >
> > However, on Mac OSX, Emacs is installed by default, but with an old
> > version.
> >
> > I have also installed Emacs via Homebrew (compiled from source) and can
> run
> > that with:
> > /Usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs
> >
> > [...]
> >
> > I was thinking I could use env somehow, like this:
> > #!/usr/bin/env emacs --script
> >
> > And then make emacs an alias or function that points to the correct
> > binary depending on system. But it's still the default Emacs that is
> > used.
>
> "env cmd" uses the cmd it finds first when checking the directories in
> your $PATH.  For example I have:
>
> --8<---------------cut here---------------start------------->8---
> % echo $PATH
>
> /home/horn/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.4.3:/usr/games/bin
> --8<---------------cut here---------------end--------------->8---
>
> Now I make a symlink to `less' that I call `emacs' inside
> /home/horn/bin:
>
> --8<---------------cut here---------------start------------->8---
> % cd ~/bin
> % ln -s /usr/bin/less emacs
> % zsh   # start a new shell
> % emacs
> Missing filename ("less --help" for help)
> --8<---------------cut here---------------end--------------->8---
>
> So as you can see, when calling `emacs' it finds the emacs-symlink to
> less first, cause that resides in a directory that comes before
> /usr/bin in PATH.
>
> HTH,
> Tassilo
>
>
>

[-- Attachment #2: Type: text/html, Size: 2375 bytes --]

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

* Re: Emacs script that works on all platforms
       [not found]   ` <mailman.0.1274964713.14889.help-gnu-emacs@gnu.org>
@ 2010-05-27 14:12     ` Pascal J. Bourguignon
  0 siblings, 0 replies; 6+ messages in thread
From: Pascal J. Bourguignon @ 2010-05-27 14:12 UTC (permalink / raw)
  To: help-gnu-emacs

Johan Andersson <johan.rejeep@gmail.com> writes:

> Hey,
>
> To bad you could not get away with an alias or function though... But it works, thanks for the tip! :)
>
> On Fri, May 21, 2010 at 3:24 PM, Tassilo Horn <tassilo@member.fsf.org> wrote:
>
>     Johan Andersson <johan.rejeep@gmail.com> writes:
>    
>     Hi Johan,
>    
>     > #!/usr/bin/emacs --script
>     >
>     > However, on Mac OSX, Emacs is installed by default, but with an old
>     > version.
>     >
>     > I have also installed Emacs via Homebrew (compiled from source) and can run
>     > that with:
>     > /Usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs
>     >
>     > [...]
>     >
>     > I was thinking I could use env somehow, like this:
>     > #!/usr/bin/env emacs --script


Well, unfortunately, someimes, env is /bin/env sometimes it's in
/usr/bin/env, so this doesn't really work either.  (Of course, one of
these system is broken, but that's the deal).

So if you do a symlink to repair env, why not for emacs?


>     Now I make a symlink to `less' that I call `emacs' inside
>     /home/horn/bin:

That's an acceptable solution for your own needs.  I even do it "per
project", installing project specific tool versions in a "opt"
directory, and generating an env.sh shell commands file to set the
PATH et al. for a specific project.  When I switch from one project to
another, I just have to source the env.sh from the opt directory of
the new project, and I get all the tools and libraries in the versions
needed by that project.

But if you want to provide a script to other users on the same
system or on another system, you need something else.



Two options I find acceptable are either your script can work with
various versions, or it should come with an "installation" procedure
that will update the #! command.

-- 
__Pascal Bourguignon__
http://www.informatimago.com


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

end of thread, other threads:[~2010-05-27 14:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-20 19:01 Emacs script that works on all platforms Johan Andersson
2010-05-21 13:24 ` Tassilo Horn
2010-05-27 12:51   ` Johan Andersson
     [not found]   ` <mailman.0.1274964713.14889.help-gnu-emacs@gnu.org>
2010-05-27 14:12     ` Pascal J. Bourguignon
     [not found] <mailman.15.1274382091.29716.help-gnu-emacs@gnu.org>
2010-05-20 20:40 ` Frédéric Perrin
     [not found] ` <3c0b258e-32ae-4ab8-b936-3d304f3e4771@34g2000prs.googlegroups.com>
2010-05-22 12:31   ` Tassilo Horn

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 read-only IMAP folder(s) and NNTP newsgroup(s).