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?

4
  • 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. Commented Aug 2, 2023 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 in the Org mode manual for details. Commented Aug 2, 2023 at 19:49
  • This question was already answered here. Thank you @shynur for the help. Commented Aug 3, 2023 at 12:03
  • @DantePicchioni: Nice search. Now you can close your question and link it to that similar question 🙂 Commented Aug 3, 2023 at 12:07

0

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.