elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.52k stars 296 forks source link

"echo vi | sudo pacman -R -" works in bash but exits without reading input in Elvish #1775

Open xiaq opened 3 months ago

xiaq commented 3 months ago

What happened, and what did you expect to happen?

Pacman is Archlinux's package manager and pacman -R - removes packages given via stdin after user confirmation.

The following works in bash:

[root@d415da14d875 ~]# echo vi | sudo pacman -R -
checking dependencies...

Package (1)  Old Version  Net Change

vi           1:070224-6    -0.31 MiB

Total Removed Size:  0.31 MiB

:: Do you want to remove these packages? [Y/n]

That is, it waits for user input before proceeding to remove the packages specified, but on Elvish the second command exits immediately:

~# echo vi | sudo pacman -R -
checking dependencies...

Package (1)  Old Version  Net Change

vi           1:070224-6    -0.31 MiB

Total Removed Size:  0.31 MiB

:: Do you want to remove these packages? [Y/n] Exception: sudo exited with 1
  [tty 1]:1:11-26: echo vi | sudo pacman -R -

Interestingly, removing the use of sudo (echo vi | pacman -R -) makes the pipeline work on Elvish.

Since pacman has its stdin redirected, it must be reading its input directly from the terminal rather than FD 0.

I have a vague suspicion that this has to do with job control, and sudo is making some assumptions that somehow don't hold in Elvish.

Output of "elvish -version"

0.20.1+archlinux4

Code of Conduct