unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: matt@excalamus.com, 67259@debbugs.gnu.org
Cc: Ihor Radchenko <yantar92@posteo.net>
Subject: bug#67259: 29.1; shell/term behavior different from other terminal emulators
Date: Sun, 30 Jun 2024 16:52:14 +0700	[thread overview]
Message-ID: <81d5867b-a9fd-4cef-9f0f-e0a42cd5e309@gmail.com> (raw)
In-Reply-To: <18be1dbb3c7.10690fc703382635.7777970297366947027@excalamus.com>

On 18/11/2023 16:55, Matt wrote:
> I'm helping to maintain Org mode's shell interaction.  The following
> was reported to the Org list.

When I noticed a discussion of dash bug causing difference in comparison 
to bash for the provided input, I have realized that Org babel shell 
issue and this emacs bugs are unrelated. This one is specific to 
interactive sessions.

> Emacs M-x shell and M-x term executing in term-line-mode both produce
> a different result

Likely `shell' and `term' issues should be treated separately and this 
bug should be cloned.

>  than expected as compared to terminal emulators
> like xterm or xfce4-terminal running Bash.  For non-Emacs terminal
> emulators, "bar" is echoed.  M-x shell and M-x term executing in
> term-line-mode do *not* echo "bar".
> 
> To reproduce with M-x shell:
> 
> 1. emacs -Q
> 2. M-x shell
> 3. Copy the following two lines:
> 
> ssh localhost "echo foo>foo_file"
> echo "bar"

I think the following allows to eliminate ssh and to demonstrate the 
issue with purely local commands. (BASH on macOS might be too old)

     fakessh() {
         bash -c 'read -t 0.2 -r; printf "fakessh read: %s\n" "$REPLY"';
     }

     fakessh
     echo next

result:

     fakessh read: echo next

instead of

    fakessh read:
    next

likely expected by users because it is behavior of xterm&Co.

since `shell' relies on specific terminal type, to get the same result 
on pasting whole snippet at once, do in xterm or a similar application

     TERM=dumb bash

With default TERM modern terminal applications and shells have bracketed 
paste enabled. It is a security measure that allows users to review 
pasted commands before executing them

<https://security.stackexchange.com/questions/39118/how-can-i-protect-myself-from-this-kind-of-clipboard-abuse>

When bash is running outside of Emacs, it is possible to paste multiple 
commands into an editor, try C-x C-e in bash prompt.

In my opinion, `shell' either should be documented as unsafe with 
warnings in docstring and manual or some workaround should be 
implemented, e.g. saving paste text into a temporary file and executing 
them.

> To reproduce with M-x term:
> 
> 1. emacs -Q
> 2. M-x term
> 3. C-c C-j to switch to term-line-mode

Notice that `term' is not affected if `term-line-mode' is not activated.

> 4. Copy the following two lines:
> 
> ssh localhost "echo foo>foo_file"
> echo "bar"

Another option to break xterm that might be closer to `term-line-mode':
Create a custom inputrc file, e.g./tmp/disable-paste.inputrc

     $include /etc/inputrc
     set enable-bracketed-paste off

and run e.g. in xterm

      INPUTRC=/tmp/disable-paste.inputrc bash

The result pasting the bunch of commands at once is

     fakessh read: echo next

I think, input from `term-line-mode' should be treated more closely to 
bracketed paste.

As a final remark, be careful with scripts running commands like ssh or 
ffmpeg that optionally read stdin. Be explicit with your intentions and 
either do

     fakessh </dev/null
     echo next

or

     fakessh <<"EOF"
     echo next
     EOF

depending on desired result.
<https://mywiki.wooledge.org/BashFAQ/089>
"I'm reading a file line by line and running ssh or ffmpeg, only the 
first line gets processed!"





      parent reply	other threads:[~2024-06-30  9:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-18  9:55 bug#67259: 29.1; shell/term behavior different from other terminal emulators Matt
2024-01-18 18:21 ` Ihor Radchenko
2024-04-18  5:55   ` Ihor Radchenko
2024-06-30  9:52 ` Max Nikulin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81d5867b-a9fd-4cef-9f0f-e0a42cd5e309@gmail.com \
    --to=manikulin@gmail.com \
    --cc=67259@debbugs.gnu.org \
    --cc=matt@excalamus.com \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).