home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] how does one test if bash shell is interactive

  • Subject: Re: [OCLUG-Tech] how does one test if bash shell is interactive
  • From: "Ian! D. Allen" <idallen [ at ] idallen [ dot ] ca>
  • Date: Thu, 11 Aug 2005 10:09:59 -0400
Adrian Irving-Beer wrote:
> When a script is launched with '&', attempting to read from the
> controlling terminal sends a TTIN signal.

Only if the process group of the spawned process is different from the
process group of the terminal.  That only happens when the spawning
shell does job control (and thus puts background processes in their own
process group).  As I said:

    You can do some kludges with process group testing under shells that
    do job control - if the process group of this script isn't the same as
    the process group of the terminal, it's probably a background script.
    (But this test fails if the shell isn't doing job control, or if
    there is no terminal at all.)

You can easily get an interactive shell that has no terminal by doing:

    > ssh localhost /bin/bash -i
    bash: no job control in this shell
    bash-3.00$ tty
    not a tty
    bash-3.00$ 

Without a terminal, everything you thought you knew about "&" doesn't work.

-- 
-IAN!  Ian! D. Allen       Ottawa, Ontario, Canada - www.ottawa.ca
       EMail: idallen [ at ] idallen [ dot ] ca   Home Page: http://www.idallen.com/
       College professor (Linux) via: http://teaching.idallen.com/
       Support free and open public digital rights:  http://eff.org/