From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?utf-8?B?RnLDqWTDqXJpYw==?= Perrin Newsgroups: gmane.emacs.help Subject: Re: Emacs script that works on all platforms Date: Thu, 20 May 2010 22:40:24 +0200 Organization: ENST Bretagne Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1291929417 2742 80.91.229.12 (9 Dec 2010 21:16:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 21:16:57 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 09 22:16:53 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQnrA-0002DY-TG for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 22:16:53 +0100 Original-Received: from localhost ([127.0.0.1]:36282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQnr9-0008E6-M7 for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 16:16:51 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!kanaga.switch.ch!switch.ch!news.in2p3.fr!in2p3.fr!news.ecp.fr!crihan.fr!news.univ-lille1.fr!utc.fr!enst-bretagne.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 44 Original-NNTP-Posting-Host: pc-df-203.priv.enst-bretagne.fr Original-X-Trace: matell.enst-bretagne.fr 1274388024 8349 10.29.221.3 (20 May 2010 20:40:24 GMT) Original-X-Complaints-To: abuse@enst-bretagne.fr Original-NNTP-Posting-Date: Thu, 20 May 2010 20:40:24 +0000 (UTC) User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:+HVz5+WqVZr7Ie1fJqfH43utuWY= Original-Xref: usenet.stanford.edu gnu.emacs.help:178311 X-Mailman-Approved-At: Thu, 09 Dec 2010 16:05:43 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:77074 Archived-At: Johan Andersson 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