On Mon, Sep 25, 2023 at 09:10:28AM +0900, John Crawley wrote: > On 24/09/2023 21:36, Greg Wooledge wrote: > > On Sun, Sep 24, 2023 at 12:03:12PM +0200, Michel Verdier wrote: > > > #!/bin/bash > > > errors=$(sudo apt-get install unknown 2>&1 1>/dev/tty) > > > echo "output: $errors" > > > errors=$(sudo apt-get install mirage 2>&1 1>/dev/tty) > > > echo "output: $errors" > > > > > > [...] > > > It waits until I type 'n' > > > > Same here. > > > Thanks for testing. > > I just tried, and yes it runs OK when the commands are in a script. > But type directly into the terminal: > > errors=$(sudo apt-get install mirage 2>&1 1>/dev/tty) > > To see the immediate abort. > (But not on Debian 11, or after invoking 'sh'.)
I actually tested in a terminal, not with a script. But the fact that *you* are getting different results with a script vs. a terminal is a clue. It doesn't give us a complete answer, but it's definitely a significant observation. The first thing you'll want to check is "type sudo", in your shell. unicorn:~$ type sudo sudo is hashed (/usr/bin/sudo) If yours is an alias, or a function, or comes from some other directory, that might explain the difference you see when running in a terminal. If that doesn't give any further clues, you might look for unusual configuration in your interactive shell. Things like a DEBUG trap, or the PROMPT_COMMAND or PS0 variables, which might trigger surprises when running commands, would be good to know about. You could also try a few experiments: 1) Run "bash --noprofile --norc" to get a vanilla shell, without any aliases, functions, weird shopts, etc. See if you still get the undesired results. 2) Try in dash, ksh, zsh or whatever other shells you have. See if you get the undesired results in any shell other than bash. (It looks like you already tried in dash, assuming sh -> dash.) 3) Create a new user account with only the default dotfiles, and see if you get the undesired results there. (You may have to add it to the sudo group.)