bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash: no job control in this shell


From: Bob Proulx
Subject: Re: bash: no job control in this shell
Date: Mon, 2 Jul 2007 14:20:37 -0600
User-agent: Mutt/1.5.9i

jrfk2@yahoo.com wrote:
> Hi Bob, a quick question if I could as I am trying to determine if my bash 
> thinks it has a tty device or not and therefore is interactive or not.

Internally bash will use the libc isatty(3) routine to determine if
the input/output files are tty devices.  In the shell these are
available in the 'test' operator as the '-t' file operator.

  $ test -t 0 && echo input is a tty
  $ test -t 1 && echo output is a tty

> I do use openpty to get a master/slave and associate the slave FD with the 
> bash. I *think* my bash is interactive, because right after the "no job 
> control" I get a bash prompt (name@name:/homelocation>).

The technique I have used is to look at $-, the option flags, and see
if 'i' is present there.

       PS1 is set and $- includes I if bash is interactive, allowing a
       shell script or a startup file to test this state.

Something like this works:

  case $- in
    *i*) echo shell is interactive ;;
  esac

Other people prefer to use a test for PS1 such as this example.

  test "${PS1+set}" = set && echo shell is interactive

Chet Ramey followed up with this information:
> > In general, this happens when bash thinks it's interactive but can't
> > obtain a handle to the controlling terminal that allows it to
> > manipulate the controlling terminal's process group.  Since that's all
> > job control really is -- switching the terminal's process group
> > between processes -- bash turns off job control if it's not available.

> So it seems like it is interactive in that I am getting prompts, the only 
> things I have seen not work are using less as an editor, and more recently 
> noticed Ctrl-C (sent as a hex '03' to bash) does not seem to interrupt 
> things.

It would be useful to see what 'stty -a' reports.  That will dump the
current tty settings, if it is a tty.  I will simulate not being on a
tty by redirecting from /dev/null.

  $ stty -a </dev/null
  stty: standard input: Inappropriate ioctl for device

On a valid tty it will dump the current settings.

  $ stty -a 
  speed 38400 baud; rows 24; columns 80; line = 0;
  intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
  eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
  werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
  -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
  -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
  -iuclc -ixany -imaxbel -iutf8
  opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 
ff0
  isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
  echoctl echoke

> I was trying to find out what the default terminal parameters and window 
> size are for openpty() as I am currently sending in NULLs for those. I 
> tried sending in window size parameters of 24x80, 640x480pix but that 
> didn't seem to make a difference to my "less" problem.

I am not familiar with openpty().  Perhaps someone else on the mailing
list will have information about that operation.

> So again, curious if it sounds like my bash shell is interactive. If it 
> sounds so, then would appreciate any leads on how i might better find out 
> why it is printing out the "no job control", so that maybe if I can rectify 
> that, it might also rectify the "less" editing problem .. thanks ...

Sorry but I don't have any hints for you there.  Personally I would
need to learn how setting up ptys is typically done these days, such
as by inspecting how 'xterm' or 'expect' or other such programs do
this.  As I recall Marc Rochkind discusses this operation in detail in
his book "Advanced UNIX Programming" and therefore might be a good
reference.  A lot of best practices have changed since the last time I
set up a master-slave pty pair and I only remember the old ways.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]