On Thu, 2 Oct 2025 23:46:30 +0200, Mike Jonkmans wrote: > > On Tue, 23 Sep 2025 05:07:18 +0200 (CEST), Pourko wrote: > > > On Thu, 18 Sep 2025 15:26:16 -0400 Chet Ramey wrote: > > > > There isn't a good way for a shell script to determine whether or not > > > > it's in the foreground or background, and whether it is in the same > > > > process group as the terminal. > > > > > > Attached is the patch that does it. > > > [...] > > > Now... > > > [ -t 0 ] && [ ! -T 0 ] > > > ...means we are running in the background. > > It is not a common case. > > Can't that check be done with something like: > trap '' SIGTTIN > if read -rd '' -n 0; then > echo Foreground > else > echo Background > fi > trap SIGTTIN
To my surprise, and contrarily to what Chet said (above), yes, one could do a check the way you suggested, and it works. But I will use Chet's words to wiggle my way out by making a distinction between "a way" and "a good way". I still feel that [ -T 0 ] is a useful thing to have. Best regards, Pourko
