Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Next: , Previous: Single Shell, Up: Shell


41.2 Interactive Inferior Shell

To run a subshell interactively, putting its typescript in an Emacs buffer, use M-x shell. This creates (or reuses) a buffer named ‘*shell*’ and runs a subshell 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>.

Emacs does not wait for the subshell to do anything. You can switch windows or buffers and edit them while the shell is waiting, or while it is running a command. Output from the subshell waits until Emacs has time to process it; this happens whenever Emacs is waiting for keyboard input or for time to elapse.

Input lines, once you submit them, are displayed using the face comint-highlight-input, and prompts are displayed using the face comint-highlight-prompt. This makes it easier to see previous input lines in the buffer. See Faces.

To make multiple subshells, you can invoke M-x shell with a prefix argument (e.g. C-u M-x shell), which 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. All the subshells in different buffers run independently and in parallel.

The file name used to load the subshell is the value of the variable explicit-shell-file-name, if that is non-nil. Otherwise, the environment variable ESHELL is used, or the environment variable SHELL if there is no ESHELL. If the file name specified is relative, the directories in the list exec-path are searched; this list is initialized based on the environment variable PATH when Emacs is started. Your .emacs file can override either or both of these default initializations.

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.

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 specify a coding system after starting the shell by using C-x <RET> p in the shell buffer. See Specify Coding.

Unless the environment variable EMACS is already defined, Emacs defines it in the subshell, with value t. A shell script can check this variable to determine whether it has been run from an Emacs subshell.


 
 
  Published under the terms of the GNU General Public License Design by Interspire