emacs: Interactive Shell

 
 40.2 Interactive Subshell
 =========================
 
 To run a subshell interactively, type ‘M-x shell’.  This creates (or
 reuses) a buffer named ‘*shell*’, and runs a shell subprocess with input
 coming from and output going to that buffer.  That is to say, any
 terminal output from the subshell goes into the buffer, advancing point,
 and any terminal input for the subshell comes from text in the buffer.
 To give input to the subshell, go to the end of the buffer and type the
 input, terminated by <RET>.
 
    By default, when the subshell is invoked interactively, the ‘*shell*’
 buffer is displayed in a new window.  This behavior can be customized
 via ‘display-buffer-alist’ (SeeWindow Choice).
 
    While the subshell is waiting or running a command, you can switch
 windows or buffers and perform other editing in Emacs.  Emacs inserts
 the output from the subshell into the Shell buffer whenever it has time
 to process it (e.g., while waiting for keyboard input).
 
    In the Shell buffer, prompts are displayed with the face
 ‘comint-highlight-prompt’, and submitted input lines are displayed with
 the face ‘comint-highlight-input’.  This makes it easier to distinguish
 input lines from the shell output.  SeeFaces.
 
    To make multiple subshells, invoke ‘M-x shell’ with a prefix argument
 (e.g., ‘C-u M-x shell’).  Then the command will read a buffer name, and
 create (or reuse) a subshell in that buffer.  You can also rename the
 ‘*shell*’ buffer using ‘M-x rename-uniquely’, then create a new
 ‘*shell*’ buffer using plain ‘M-x shell’.  Subshells in different
 buffers run independently and in parallel.
 
    To specify the shell file name used by ‘M-x shell’, customize the
 variable ‘explicit-shell-file-name’.  If this is ‘nil’ (the default),
 Emacs uses the environment variable ‘ESHELL’ if it exists.  Otherwise,
 it usually uses the variable ‘shell-file-name’ (SeeSingle Shell);
 but if the default directory is remote (SeeRemote Files), it
 prompts you for the shell file name.
 
    Emacs sends the new shell the contents of the file
 ‘~/.emacs_SHELLNAME’ as input, if it exists, where SHELLNAME is the name
 of the file that the shell was loaded from.  For example, if you use
 bash, the file sent to it is ‘~/.emacs_bash’.  If this file is not
 found, Emacs tries with ‘~/.emacs.d/init_SHELLNAME.sh’.
 
    To specify a coding system for the shell, you can use the command
 ‘C-x <RET> c’ immediately before ‘M-x shell’.  You can also change the
 coding system for a running subshell by typing ‘C-x <RET> p’ in the
 shell buffer.  SeeCommunication Coding.
 
    Emacs sets the environment variable ‘INSIDE_EMACS’ in the subshell to
 ‘VERSION,comint’, where VERSION is the Emacs version (e.g., ‘24.1’).
 Programs can check this variable to determine whether they are running
 inside an Emacs subshell.