Bug #1397
openjobs -l output inconsistency when called from script
Description
Salute.
The jobs(1) utility gives different output when called from a script and when
from an interactive shell.
[beket@voyager ~] cat testjobs.sh #!/bin/sh sleep 30 & jobs -l [beket@voyager ~] sh testjobs.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 testjobs.sh [1] + 27159 Running sleep 30
SunOS 5.10:
tuxillo@solaris$ /usr/xpg4/bin/sh testjobs.sh [1] + 11754 Running <command unknown>
FreeBSD: same as us. (kindly reported by vstemen at #dragonflybsd).
Any thoughts ?
Best regards,
Stathis
Updated by tuxillo over 2 years ago
- Description updated (diff)
- Assignee deleted (
0)
Updated by tuxillo over 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 #!/bin/sh # $FreeBSD: src/usr.bin/alias/generic.sh,v 1.2 2005/10/24 22:32:19 cperciva Exp $ # $DragonFly: src/usr.bin/alias/generic.sh,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 /usr/bin/jobs $ bash $ which jobs /usr/bin/jobs
Now if you run the testjobs.sh in different shells, you might get different results, bash and sh behaving the same way:
$ sh testjobs.sh [1] + 814254 Running $ csh testjobs.sh [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.