Elisp: Get Command Line Arguments

By Xah Lee. Date: . Last updated: .

Get Command Line Arguments

argv

A built-in variable. Its value is a list. Each element is a item from the command line.

when you run emacs lisp script from terminal

emacs --script myscript.el arg1 arg2

;; 2023-08-03
;; a test emacs script

;; save this file as xtest.el
;; run in shell like this
;; emacs --script xtest.el a b c

;; print arguments from command line
(message "argv 0: %s" (elt argv 0))
(message "argv 1: %s" (elt argv 1))
(message "argv 2: %s" (elt argv 2))
(message "argv 3: %s" (elt argv 3))
emacs lisp script 2023-08-03
emacs lisp script 2023-08-03

Reference

2011-07-22 Thanks to Piotr Chamera [piotr_cham…@poczta.onet.pl], Swami Tota Ram Shankar [tota_…@india.com].

Run Elisp Script in Terminal