[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug with edit-and-execute-command and multiline commands
From: |
Emanuele Torre |
Subject: |
bug with edit-and-execute-command and multiline commands |
Date: |
Sat, 7 Aug 2021 03:49:48 +0200 |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin'
-DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc'
-DSYS_BASH_LOGOUT='/etc/bash.bash_logout'
-DNON_INTERACTIVE_LOGIN_SHELLS
uname output: Linux t420 5.10.54-1-lts #1 SMP Wed, 28 Jul 2021
15:05:20 +0000 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.1
Patch Level: 8
Release Status: release
Description:
rwp suggested me to re report this bug via bashbug instead of using
savannah since it is the preferred method.
Here is the original savannah support report:
https://savannah.gnu.org/support/?110523
edit-and-execute-command seems to have odd and unintened behaviour
when used while bash is reading multiline commands that are
inconsistent between bash versions and patch levels.
Here are the main ones I noticed in bash 5.1-8.
If I type-in a multiline command in an interactive bash shell and
then use edit-and-execute-command, that command will get executed,
but bash will continue reading for the multiline command.
Example: if I type-in "if true" newline "then echo hi" newline "else
echo hello" newline "fi", and then I press \C-x\C-e (to trigger
edit-and-execute-command) and exit the editor, "hi" will be printed;
then, if I enter "echo hey" newline "echo good morning" and again
\C-x\C-e and close the editor, "hi", "hey", and "good morning" get
printed.
The behaviour is a bit different (but still probably not intended)
if the first line is "\" and the second line is a simple commands.
Example: "\" newline "ls /" \C-x\C-e, when I exit the editor the
command is executed; then:
* if I type-in "echo hi" and then press enter, "hi" is printed and
I get back to the regular bash prompt.
* if I type-in "echo hi" and then use \C-x\C-e, the editor opens
with "ls / echo hi" and if I close it, "ls / echo hi" is run, and
then it keeps reading lines for the command; if I use \C-x\C-e,
it keeps adding the line as arguments of the command, otherwise,
if I press return, it executes the last line as a standalone
command and then it stops reading the multiline command and goes
back to the regular prompt.
There is an inaccuracy in the second example of the savannah request
that I have corrected here: I say that behaviour occurs for simple
commands, when it actually only occurs if the first line is "\" and
the second line is a simple command: "ls \" newline "/" behaves
like the first example.
NB: The second part of the second example only occurs the simple
command is an external command: "\" newline "echo hi" \C-x\C-e
"echo hello" \C-x\C-e opens the editor with "echo hi; echo hello",
not "echo hi echo hello"
rwp told me that he experienced different (but still weird)
behaviours on older bash versions.
Here is the conversation we had on the #savannah of irc.libera.chat:
<rwp> Meanwhile... For bash I think your best process is to send an
email to the bug-bash AT gnu.org mailing list.
<emanuele6> oh, ok.
<rwp> That's where Chet mostly handles bash bugs.
<emanuele6> thank you for the help, rwp!
<rwp> I'm just reading your bug reproducer very carefully now...
<rwp> That does seem pretty weird behavior around C-x C-e which I
can't think of a time I have ever done on the command line
myself before.
<rwp> I actually get different behavior than what you report. But it
is still not expected either. So something bizarre going on
there.
<rwp> What I see is that it doesn't actually execute the command.
And if I am left looking at the PS4 "> " prompt.
<rwp> All attempts to terminate the command at that point result in
a "bash: syntax error near unexpected token `;'" message.
<emanuele6> oh
<emanuele6> i also tried my examples with `bash --norc` and they had
the same behaviour
<emanuele6> i mean the same behaviours that i described on the sr
<emanuele6> so maybe it is your configuration
<rwp> I am running bash-5.1-3 here. You are running 5.1-8. But it is
different yet again in bash-4.4-5 too.
<emanuele6> i see
<rwp> In 4.4 I get an immediate syntax
"bash: syntax error near unexpected token `fi'"
<rwp> Good bug!
Repeat-By:
example 1:
$ EDITOR=vi |
$ \ |
> echo hello | enter ^X^E; vi will open with "echo hello"; exit with :q
hello |
> echo hi | the prompt keeps showing PS4 instead of PS1; hit return
hi |
$ |
example 2 (this only occurs with external commands like ls(1), not
with echo):
$ EDITOR=vi |
$ \ |
> ls / | enter ^X^E; vi will open with "ls /"; exit
[contents of /] |
> /tmp | enter ^X^E; vi will open with "ls / /tmp"; exit
[contents of /] |
[contents of /tmp] |
> echo hey | hit return
hey |
$ |
example 3:
$ EDITOR=vi |
$ if true |
> then echo hi |
> else echo hello |
> fi | enter ^X^E; vi will open with
"if true; then echo hi; else echo hello; fi"; exit
hi |
> echo hey |
> echo morning | enter ^X^E; vi will open with what it had before
plus "; echo hey; echo morning"; exit
hi |
hey |
morning |
> echo not run |
> ^C | enter ^C
$ |
I had also recorded a GIF showing me repeating examples similar to
"example 1" and "example 3" that might help understand the bug
better.
Here is a link to download it from savannah:
https://savannah.gnu.org/support/download.php?file_id=51741
Also here is a paste with some examples by rwp:
https://paste.debian.net/plain/1206849
- bug with edit-and-execute-command and multiline commands,
Emanuele Torre <=