On Thu, Oct 2, 2025 at 5:48 PM Mike Jonkmans <[email protected]> wrote:
>
> On Thu, Oct 02, 2025 at 02:56:32PM +0200, Pourko via Bug reports for the GNU 
> Bourne Again SHell wrote:
>
> 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

Unfortunately, this relies on non-portable behavior of read(2) with a
size argument of 0. Error detection is not required in this case per
POSIX [1] and, indeed, on macOS `read -rd '' -n 0' returns 0 when called
in a background job.

[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/read.html

> > On Tue, 23 Sep 2025 05:07:18 +0200 (CEST), Pourko wrote:
> > > Now...
> > > [ -t 0 ] && [ ! -T 0 ]
> > > ...means we are running in the background.
> >
> > It puzzles me that I seem to be the only one excited by this.
> > Don't you find it to be a useful thing to have?

I wonder if the `tcgetpgrp((fd) == getpgid(0)' test you propose wouldn't
be more appropriate for `read -n0' (or some other option combination) to
do rather than have it as a `test' operation.

  • [PATCH] builtin: ... pourko--- via Bug reports for the GNU Bourne Again SHell
    • Re: [PATCH] ... Pourko via Bug reports for the GNU Bourne Again SHell
      • Re: [PAT... Mike Jonkmans
        • Re: ... Pourko via Bug reports for the GNU Bourne Again SHell
        • Re: ... Pourko via Bug reports for the GNU Bourne Again SHell
        • Re: ... Pourko via Bug reports for the GNU Bourne Again SHell
        • Re: ... Grisha Levit
          • ... Mike Jonkmans
          • ... Pourko via Bug reports for the GNU Bourne Again SHell

Reply via email to