Emacs: Run Shell in Emacs

By Xah Lee. Date: . Last updated: .

Start Shell in Emacs

Alt+x shell.

When in shell, to run the previous shell command, press Ctrl+.

emacs shell 2014-08-22
running bash in emacs 2014-08-22
emacs shell 2016-07-18
running bash in emacs 2016-07-18

[see also Emacs Init: Change Default Shell (PowerShell)]

Start a Second Shell in Emacs

Ctrl+u Alt+x shell

Call a shell command once

Alt+x shell-commandAlt+!】 to run a single shell command.

Send text selection to a shell command

Select a region, then Alt+x shell-command-on-regionAlt+|】.

For example, select a region, then type Alt+| wc -l Enter. This will print line count of region.

You can have the result replace the selected region. To do that, do universal-argumentCtrl+u】 before calling the shell on region command.

My shell doesn't work in Windows?

Most problems are probably caused by incorrect environment variable setup. See: Emacs in Microsoft Windows FAQ.

Shell in Emacs