Running shell commands from Emacs

Emacsrun a shell interactively with input and output to an Emacs buffernamed '*shell*' or run a shell inside a terminal emulator windows.

M-!cmd RET         Run the shell command line cmd and display the output (shell-command).

M-|cmd RET          Run the shell command line cmd with region contents as input;optionallyreplace the region with the output

                              (shell-command-on-region).

M-xshell               Run the shell command line cmd asynchronously, and displaythe output(async-shell-command).

M-xterm               Run a subshell with input and output through an Emacs buffer.Fullterminal emulation is available.


1.Multiple subshell

Tomake 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 (orreuse) a subshell in that buffer. You can also rename the '*shell*' bufferusing M-x rename-uniquely, then create a new '*shell*' buffer usingplain M-x shell. Subshells in diffent buffers run independently andin parallel.


2.Shell history ring

M-p

C-UP          Fetch the next earlier old shell command.

M-n

C-DOWN    Fetch the next later old shell command.

M-r            Begin an incremental regexp search of old shellcommands.

C-cC-x       Fetch the next subsequent command from the history.

C-c.           Fetch one argument from an old shell command.

C-cC-l       Display the buffer's history of shell commands in anotherwindow(comint-dynamic-list-input-ring).


3.Emacs terminal Emulator

Torun a subshell in a terminal emulator, use M-x term. This create (orreuses) a buffer named '*terminal*', and runs a subshell with input comingfrom your keyboard, and output going to that buffer. Theterminal emulator uses Term mode, which has two input modes. In linemode, Term basically acts like Shell mode. In char mode, each characteris sent directly to the inferior subshell, as "terminal input". Any"echoing" of your input is the responsibility of thesubshell. The soleexception is the terminal escape character, which by default is C-c.Any "terminal output" from the subshell goes into thebuffer, advancingpoint. Tomake multiple terminal emulators, rename the buffer '*terminal*' to somethingdiffent using M-x rename-uniquely just as with Shell mode.


4.Term mode

Toswitch between line and char mode, use these commands:

C-cC-j            Switch to line mode. Do nothing if already in line mode.

C-cC-k           Switch to char mode. Do nothing if already in char mode.

C-cC-c            Send a literal C-c to the sub-shell.

C-cchar          This is equivalent to C-x char in normal Emacs. For example, C-co invokes the global binding of C-x o.


5.Remote host shell

Youcan login to remote computer, using whatever commands you would froma regular terminal, from a Term window. Aprogram that asks you for a password will normally suppres echoing ofthe password, so the password will not show up in the buffer. This willhappen just as if you were using a real terminal, if the buffer ischar mode. If it is in line mode, the password is temporarilyvisible, butwill be erased when you hit return.(This happens automatically; thereis no special password processing.) Whenyou log in to a diffent machine, you need to specify the type of terminalyou're using, by setting the TERM environment variable in the environmentfor the remote login command. (If you use bash, you do that bywriting the variable assignment before the remote login command, withoutseparating comma.) Terminal types 'ansi' or 'vt100' will work onmost systems.


NOTE: This article comes from GNU Emacs Manual.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值