Getting the output of 'jobs' into a shell variable

Getting the output of 'jobs' into a shell variable

Post by Erik E. Rantap » Sun, 07 Mar 1993 08:09:30



Is it possible to get the output of 'jobs' into a shell variable,
without having to resort to using a temporary file?

The problem is, of course, that 'jobs' gives the wrong output if
run in the background.  Hence the use of backquotes won't work.

Actually, all I need is the number of background jobs for which the
following 'kludge' works in bash:

  jobs -p | wc -w | { read x; exit $x }
  n=$?
  # ... n now holds the number of background jobs ...

But then, is there, in general, a way of grabbing the output of a command
which cannot be run in the background?

--
 "A witty saying proves nothing."
                -- Voltaire


 
 
 

Getting the output of 'jobs' into a shell variable

Post by Chet Ram » Tue, 09 Mar 1993 22:55:36



Quote:>Is it possible to get the output of 'jobs' into a shell variable,
>without having to resort to using a temporary file?

bash and ksh (and possibly zsh) allow `jobs' to be run in subshells
when it won't*things up.  You can use

n=`jobs | wc -l`

to do what you want in either.

Chet
--
``The use of history as therapy means the corruption of history as history.''
        -- Arthur Schlesinger



 
 
 

1. ksh93 - Ctrl-c of fg'd output producing job causes shell to be stuck

Hi,

I am using FreeBSD 4.8-Release; ksh93 (o+, 20030621) & bash are the
shells i most often use.

Consider the following set of commands issued (output is not
shown) in xterm...

  script log yes &  #  runs only in fg, produces output
  fg                #  bring in fg to see y's flying by
  Ctrl-c            #  keyboard interrupt

...the set executes and ends w/o drama or side effects in bash.

In ksh93, however, after Ctrl-c, nothing is echoed or blind typing
seems to have no effect.  Only things that happens is updated $PS1
is printed after typing each Ctrl-c, or $PS1 & ">"  after Ctrl-\,
Ctrl-c.

Sending a signal to the above script command running does not cause
any problems however.  (I tried -KILL, -INT, -TERM.)  Things behave
as they do in bash.

Why does the above command sequence causes it to seemingly ignore
the terminal/keyboard?  Are there any solutions?

It is even more bizarre that any of the following two sets does not
cause non-responsive terminal/keryboad...

  script log yes & sleep 2; fg
  Ctrl-c

  script log yes & fg
  Ctrl-c

Also, there is no problem w/ just "script log yes; Ctrl-c", i.e.
interrupt the program while it is running, w/o going in background.

Thanks.

  - parv

--
In order to reach me, do away w/ WhereElse in the address.

A programmer, budding Unix system administrator, and amateur photographer
seeks employment: http://www103.pair.com/parv/work/

2. Outlook with SSL from stunnel with qpopper

3. bash Q: +/- in output of 'jobs'?

4. Users having probs logging into Linux system, get '/home/...' doesn't exist.

5. Redirecting 'at' job output

6. In trouble - how to wipe out slackware 3.2 and start from scratch?

7. how to pipe the output of the builtin 'jobs' command ?

8. Trio3d only able to get 16 color mode

9. 'at' jobs - getting rid of mail

10. Odd 'w', 'who' and 'tty' output

11. Job control in the 'rc' shell.

12. C-SHELL BUG - @ variable = 'expression' - LONG.

13. "Directory: <pwd>" output for every 'cd' in tcsh shell