0

I login to a computer with SSH. In my home directory, there is a file called test.sh with a bunch of BASH code in it. I start editing it with emacs -nw test.sh. It is a large file, and I want to test only a portion of the code.

How can I highlight a portion of code and tell Emacs to run only that portion in my home (i.e., working) directory and show the output within Emacs?

Drew
  • 75,699
  • 9
  • 109
  • 225
  • Possible. You can create a subprocess getting input from your selected region. ||| Moreover, there is a command named `shell-command-on-region`, you can have a try. – shynur Aug 02 '23 at 19:01
  • It is very unlikely that a portion of a shell program will be able to run stand-alone: even if you choose the region correctly, so you don't cause syntax errors, it is likely that you will be using variables or functions that are defined outside the region - resulting in errors or problematic results. I would use an Org mode file with a code block, where I could cut-and-paste the code and make additional changes (e.g. add variable definitions) before running the block. See [Working with Source Code](https://orgmode.org/manual/Working-with-Source-Code.html) in the Org mode manual for details. – NickD Aug 02 '23 at 19:49
  • This question was already answered [here](https://emacs.stackexchange.com/a/48050/41148). Thank you @shynur for the help. – Dante Picchioni Aug 03 '23 at 12:03
  • @DantePicchioni: Nice search. Now you can close your question and link it to that similar question – shynur Aug 03 '23 at 12:07

0 Answers0