Elisp: Run Elisp Script in Shell

By Xah Lee. Date: . Last updated: .

You can run emacs lisp script in shell (terminal), using the --script option. For example:

emacs --script process_log.el

Here's a table of most useful options for running emacs lisp as a script.

--no-init-file or -q
Do not load your init files {~/.emacs, ~/.emacs.el, ~/.emacs.d/init.el} nor site-wide default.el.
Do not load the site-wide site-start.el.
Do not launch emacs as a editor. Use it together with --load to specify a lisp file. This implies --no-init-file but not --no-site-file.
--load="path" or -l path
Execute the elisp file at path.
--script path
Run emacs like --batch with --load set to path.

For a complete list, see:

What is site-start.el?

The site-start.el is a init file for site-wide running of emacs.

It pretty much means a init file for all users of this emacs installation. It may be added by a sys admin, or it may be part of a particular emacs distribution (For example, Carbon Emacs, Aquamacs Emacs, etc.).

You can usually find this file in the directory where emacs is installed, if it exists. Typically in a directory named “site-lisp”. For example, ~/apps/emacs-25.1/site-lisp/. But the file can be anywhere in emacs load-path.

(info "(elisp) Init File")

(info "(elisp) Library Search")

Prepare Your Emacs Lisp Script to Run in Batch Mode

When you write a elisp script to run in batch, make sure your elisp file is:

  1. self-contained; Doesn't depend on anything from your emacs init file.
  2. Explicitly load all libraries it needs (using require or load).
  3. Has necessary load path set in the script (For example, (add-to-list 'load-path lib_path)) if it needs libs that's not part of standard GNU emacs install, just like you would with a Python or Ruby script.

How to start emacs on a Mac from command line?

If you are on a Mac, call it from the command line like this:

/Applications/Emacs.app/Contents/MacOS/Emacs --script=name.el

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys


ELisp Examples

ELisp Write Major Mode



Basic Functions

Writing Command

Writing Script

Lisp Data Structure

Lisp Symbol

Elisp Misc