Results 1 to 4 of 4
Wow, I've searched for a week now, and just as puzzled as before. Rather than post a long script or try to explain my problem the hard way, I've reduced ...
- 02-06-2009 #1Just Joined!
- Join Date
- Feb 2009
- Posts
- 3
fg: no job control, in script
Wow, I've searched for a week now, and just as puzzled as before. Rather than post a long script or try to explain my problem the hard way, I've reduced the problem I'm having to something very simple:
#!/bin/bash
sleep 9 &
jobs
fg %1
All I get is "fg: no job control" from the fg command. I did get some hits from a web search, but mainly having to do with stuff I did not understand, like tty permissions during some install procedure or somesuch. And nothing relevant in the bash documents, except some obscure text about something about jobs not being in the right process id?
Any clues why the above doesn't work, or better, HOW to get it to work?
(BTW, in case anyone is wondering, the actual scripts are trying to start a process in the background that has to start first, but eventually starts a console app and suspends. In the meantime, I have to start another process in the background, and then need to bring the first one to the foreground to allow it to unsuspend and execute. I actually got it to work, but only by sourcing it directly from my crappy default tcsh shell, which is not what I need, but only proof of concept). Pheh ....
Cheers,
dim_bulb
- 02-06-2009 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Turning monitor mode on seems to make the simple script work:
Producing:Code:#!/usr/bin/env bash # @(#) s1 Demonstrate job control in script with "monitor" mode. echo set +o nounset LC_ALL=C ; LANG=C ; export LC_ALL LANG echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG" echo "(Versions displayed with local utility \"version\")" version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) set -o nounset # Turn on monitor mode. set -m echo echo " Results:" sleep 10 & /usr/bin/pgrep -l sleep jobs fg %1 echo " Done." exit 0
Search for monitor in man bash for details ... cheers, drlCode:% ./s1 Environment: LC_ALL = C, LANG = C (Versions displayed with local utility "version") OS, ker|rel, machine: Linux, 2.6.11-x1, i686 Distribution : Xandros Desktop 3.0.3 Business GNU bash 2.05b.0 Results: 29290 sleep [1]+ Running sleep 10 & sleep 10 Done.
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 02-06-2009 #3Just Joined!
- Join Date
- Feb 2009
- Posts
- 3
Oh my god! Thank you so much. By the wee hours of last night, I was on that track, but none of the bash manuals explained how to actually change the options to the shell. I kept seeing something about actually starting bash itself with options, and at one point tried various versions of
#!/bin/bash -o monitor
to no avail! I just can't believe out of the 50 or so searches I did all week about job control, scripting, etc., not one single mention was made about "oh hey, if you want to actually USE the job commands in a script, just do set -m"
Thanks again, drl!!
- 02-06-2009 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
You are welcome, and a belated welcome to the forums.
I think the expanded command:
is probably better for maintainability -- it at least has the string monitor in it. A slight disadvantage is that it may appear that the option is being turned off because of the appearance of -o.Code:set -o monitor
One would need to put together a few pieces of information from man bash in order to solve this on one's own. The *nix man pages are not tutorial vehicles, and, in particular, some Linux man pages are not well-written. I usually cite Sun man pages as a model because they often provide examples. Of course something as large as a shell man page can be daunting. Even skimming the O'Reilly book Learning the bash Shell, 2nd does not reveal a mention of monitor, nor an example of it in the job control sections -- but I still use it because of the discussions and examples. And yet this is not a predicament solely for novices. I have been using Unix-like systems for a long time and just this week I found out about some features of xargs that are not apparent from the man page. Apparently, we all will need to be a intrepid explorers to find some of these features.
Glad it has worked out so far. Best wishes ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


