I have a large bash script and I need to rerun certain lines of code. Normally I would comment out any line I don't want to run and then execute the file on the shell. But that is rather cumbersome. I'd much rather select the lines I want to execute and do something like M-x execute-selected-lines-in-the-current-directory
. Is there something like that?
Asked
Active
Viewed 610 times
2

user2740
- 539
- 1
- 5
- 10
-
What does the substring `in-the-current-directory` in the assumed command name `execute-selected-lines-in-the-current-directory` mean? Could you elaborate please? Do you want to run the selected lines in a directory different from the `default-directory` of the current shell script file buffer? – Tobias Feb 25 '19 at 15:23
2 Answers
2
Use M-| (shell-command-on-region
) then sh
to pipe the current region to Bash. It works because bash
supports running program from STDIN, e.g.,
~ $ echo 'date' | sh
Mon Feb 25 21:54:51 CST 2019
M-| runs via a fresh shell every time, so I'm not sure if it can work in your case.

xuchunyang
- 14,302
- 1
- 18
- 39