Re: Question on background jobs



Joachim Schmitz wrote:
Barry Margolin wrote:
In article
<71394f16-cdc8-4d97-998f-216c58ac9e19@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
bsh <brian_hiles@xxxxxxxxxxxxxx> wrote:

On Jun 24, 12:54 pm, Chad <cdal...@xxxxxxxxx> wrote:

Then how come you can't have job control in a non-interactive shell
(via a script)

It does. Investigate [in at least ksh(1)] the monitor shell option:

set -o monitor

From the ksh(1) manpage:

If the monitor option of the set command is turned on, an
interactive shell
associates a job with each pipeline. It keeps a table of current
jobs, printed
by the jobs command, and assigns them small integer numbers. When a
job is started asynchronously with &, the shell prints [a line
associating
that command with a job number].

That description says that the option affects interactive shells, his
question was about non-interactive shells.

Note that ksh and bash (and probably other shells) have a -i option
to make it interactive even if it's executing a script. So if you
really wanted to have job control enabled in a script, you could
start it with:

#!/bin/ksh -i

I've never tried this so I'm not sure how it would affect things.
I just did (see the thread about "Running a command for a limited
time". "set -m" is switching on job control for non-interactive shells
After being hinted about that switch by Bill Marcum...

#!/bin/ksh -m

Bye, Jojo


.



Relevant Pages

  • Re: detect shell script language
    ... In the 'old' days, when a user typed in a command, the interactive shell would immediately pass it off to 'exec' to execute. ... So, on return from exec with an error status, the shell would fork a copy of itself to try and run the script. ... As a result of the above, it was hard to tell whether the script was a Bourne shell or C shell, so the convention was introduced of using the Bourne shell no op command, as the first line in a Bourne shell script. ...
    (Debian-User)
  • Re: awk here documents
    ... script called from shell to produce some pre-formatted blocks of code ... awk variable: ... or awk quotes with shell quotes ...
    (comp.unix.shell)
  • Re: misc/149335: shell script runs on Linux but not on freebsd
    ... to develop a smarter install script. ... Even if I correct the shell calls ... Looks like the Linux emulator is only 32 bit. ... I would like to see if I can get the x64 to install but if not I think the ...
    (freebsd-questions)
  • Re: When to use a function
    ... as expensive as calling a new script. ... handling may be easier to handle if you're in the same shell process. ... but some carefully chosen globals can make things simpler. ... all you are going to do is call an external program anyhow then there is ...
    (comp.unix.shell)
  • Re: Call for input on comp.unix.shell FAQ
    ... >> questions and just tell people to FAQ it. ... The other level is how to write shell scripts. ... How can I remove whitespace characters within file names? ... Why one shouldn't use "echo" in a script? ...
    (comp.unix.shell)