BG1REN's BLOG

Technology, Life, and Infinite Possibilities...


Running Emacs Lisp Scripts

Take a look at this script (hello.el):

#!/usr/bin/env -S emacs -Q --script

(message "Hello, Emacs!")
  1. The first line #!/usr/bin/env -S requires the -S flag. Without it, env would treat emacs -Q --script as a single command rather than separate command and arguments.
  2. The -Q flag for emacs ensures it starts without loading any user configuration files, providing a clean slate.
  3. The --script flag tells emacs to execute the script. If running directly from the command line, you would use emacs -Q --script hello.el.

Execution result of the above script:

Hello, Emacs!