Mac – Run Emacs within Bash

bashemacsterminal

I am looking for a way in Bash to run something within Emacs. For example, if you run emacs, press esc+X then type "life," you get a little simulation of Conway's Game of Life. How could this be done via Bash?

Don't have much so far:

#!/bin/sh
emacs

I've read about using ^] and such but doing

#!/bin/sh
emacs
^]

does not work (neither does ^[)

Basically, how can I simulate all of these key presses in Bash, with the default Mac Emacs (22.1.1)?

Best Answer

Use emacs -f <function>

E.g.: emacs -f life in this case.

GNU Emacs Manual