16

In sh-mode in Emacs, I was looking for a way to execute a shell script in the current buffer directly like the C-c C-c in Python-mode. Using M-! is really tiring. Any amount of googling doesn't help. Is this possible?

3 Answers 3

14

M-| is shell-command-on-region

so if you want to execute the whole buffer, C-x h M-| or you can rebind to something more convenient.

Sign up to request clarification or add additional context in comments.

2 Comments

Mmm... I get the prompt "Shell command on region:" in the mini-buffer. How is this supposed to work? I thought the region selected was going to be executed in a shell...
@nephewtom just type sh in prompt and then contents of buffer will be run via shell
7

When I am editing a shell script called foo.sh, I set the variable compile-command to "foo.sh". Then, C-c m (compile) or C-c r (recompile) executes the script. C-c m lets me add or modify arguments to the script before running it, C-c r will run it with the last arguments used.

Comments

1

Rebind M-! to something you like better, you can do it to the local keymap to just affect the shell buffer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.