Search code examples
shellemacscommand-line-argumentselisp

Emacs shell scripts - how to put initial options into the script?


Inspired by Stack Overflow question Idomatic batch processing of text in Emacs? I tried out an Emacs shell script with the following headline:

#!/usr/bin/emacs --script 

I put some Emacs Lisp code in it, and saved it as textfile rcat.

Since the --script option does not prevent the loading of the site-start file, I had a lot of

Loading /etc/emacs/site-start.d/20apel.el (source)...
Loading /etc/emacs23/site-start.d/35elib-startup.el (source)...
Loading /etc/emacs23/site-start.d/50auctex.el (source)...

messages in the Bash shell (stdout). I can prevent that by calling

rcat --no-site-file

or

rcat -Q

but not by changing the headline in the script:

 #!/usr/bin/emacs --script --no-site-file

Is there a way to pass additional options to Emacs inside such a script file instead of doing it later on the commandline?


Solution

  • You could always change #!/usr/bin/emacs to something like #!/home/thorsten/bin/emacs-no-site-file, and set that up as:

    #!/bin/sh
    exec /usr/bin/emacs --no-site-file "$@"
    

    If this doesn't work for you, or if you wish your script to be portable, then see Gilles' answer below for a more robust (and slightly funky :) approach.