Bug #1397


jobs -l output inconsistency when called from script

Added by Anonymous about 15 years ago. Updated about 2 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:



The jobs(1) utility gives different output when called from a script and when
from an interactive shell.

[beket@voyager ~] cat
sleep 30 &
jobs -l
[beket@voyager ~] sh 
[1] + 10005 Running           
[beket@voyager ~] sleep 30 &
[1] 10006
[beket@voyager ~] jobs -l
[1]+ 10006 Running                 sleep 30 &
[beket@voyager ~] 

It is not clear whether the jobs(1) should work at all inside a script. POSIX
says that since it doesn't fall into the 'special' built-in category a new
environment (subshell?) would be created upon its invocation. Even this is true,
the jobs aren't specific to the shell environment, so they should be visible to
jobs(1). And in any case, the command should either print nothing or print all
the fields.

NetBSD 5.0:

$ sh 
[1] + 27159 Running           sleep 30

SunOS 5.10:

tuxillo@solaris$ /usr/xpg4/bin/sh 
[1] + 11754      Running                 <command unknown>

FreeBSD: same as us. (kindly reported by vstemen at #dragonflybsd).

Any thoughts ?

Best regards,

Actions #1

Updated by tuxillo about 2 years ago

  • Description updated (diff)
  • Assignee deleted (0)
Actions #2

Updated by tuxillo about 2 years ago

  • Status changed from New to Feedback
  • Assignee set to tuxillo
  • % Done changed from 0 to 90

The jobs(1) utility calls whatever builtin the current shell uses, or it is directly bypassed by the shell itself, example:

$ cat /usr/bin/jobs 
# $FreeBSD: src/usr.bin/alias/,v 1.2 2005/10/24 22:32:19 cperciva Exp $
# $DragonFly: src/usr.bin/alias/,v 1.3 2007/08/05 16:09:50 pavalos Exp $
# This file is in the public domain.
builtin ${0##*/} ${1+"$@"}

And in every shell:

$ tcsh
$ which jobs
jobs: shell built-in command.
$ sh
$ which jobs
$ bash
$ which jobs

Now if you run the in different shells, you might get different results, bash and sh behaving the same way:

$ sh 
[1] + 814254 Running          
$ csh 
[1] 814260
[1]  + 814260 Running                       sleep 30

Even in Solaris there is a <command unknown> with the job listing, so I'd rather have not output at all.

If further comments are needed, let us know, otherwise we will close this issue.


Also available in: Atom PDF