#1043320 bash: Background loop with sudo and wait cause terminal problems

Package:
bash
Source:
bash
Description:
GNU Bourne Again SHell
Submitter:
Bruce Momjian
Date:
2023-08-09 14:18:05 UTC
Severity:
normal
#1043320#5
Date:
2023-08-09 03:04:39 UTC
From:
To:
Dear Maintainer,

   * What led up to the situation?
A script that worked fine on Debian 11 caused terminal corruption on Debian 12.
   * What exactly did you do (or not do) that was effective (or
     ineffective)?
I was able to create a minimal test case to illustrate the problem.
   * What was the outcome of this action?
The problem is that output loses carriage returns and echo is turned off for the terminal on script exit.
   * What outcome did you expect instead?
I expected no terminal device corruption.  stty sane does fix the terminal after the failure.

Here is a test case:

	#!/bin/bash

	for DIR in $(jot 5)
	do	{ echo 1; sudo -u $USER -- echo test > /dev/null; echo 2; } | cat &
	done

	wait

Running this on my system outputs the '2' with line feeds and no carriage returns, and on exit, the terminal has echo turned off.  stty sane fixes it.

#1043320#10
Date:
2023-08-09 13:56:30 UTC
From:
To:
FYI, this problem does not happen with sh/dash.