emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash source code block: problem after ssh commands


From: Ihor Radchenko
Subject: Re: bash source code block: problem after ssh commands
Date: Mon, 06 Nov 2023 13:32:16 +0000

Bruno Barbier <brubar.cs@gmail.com> writes:

> IIUC, the elisp expression:
>
>     (process-file "bash" "/tmp/test.sh")
>
> is more equivalent to:
>
>     cat /tmp/test.sh | bash
>
> i.e. the shell is getting the commands from stdin.  Thus, any command
> that uses stdin might change what gets executed or not.

Looking at `org-babel-sh-evaluate', it should be enough to specify
:shebang, :cmdline, or :stdin header argument to force using script
rather than channel source block as input to bash:

#+begin_src shell :results output :cmdline bash
exec 0>&-
echo OK
#+end_src

#+RESULTS:
: OK


#+begin_src shell :results output :cmdline bash
echo 1
read -p "Next command? " NEXT_COMMAND
echo 2
echo 3
#+end_src

#+RESULTS:
: 1
: 2
: 3

I am wondering about the possible downsides of using script approach
instead of stdin redirection.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]