Bug 24591

Summary: jobs command differs in interactive vs. non-interactive /bin/sh
Product: Base System Reporter: Andre Albsmeier <Andre.Albsmeier>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.2-STABLE   
Hardware: Any   
OS: Any   

Description Andre Albsmeier 2001-01-24 06:50:00 UTC
When the 'jobs' command is used in /bin/sh, its output differs
depending if sh is an interactive vs. non-interactive shell.

Fix: 

Unknown. In /src/bin/sh/jobs.c,v 1.27.2.2 in line 337, the code

	out1str(ps->cmd);

normally outputs the command which doesn't work in non-interactive shells.
How-To-Repeat: 
andre@bali:~>/bin/sh 
$ sleep 10 &
$ jobs
[1] 76401                     sleep 10
$ 

vs.

andre@bali:~>cat jobstest 
#!/bin/sh
sleep 10 &
jobs
andre@bali:~>./jobstest 
[1] 76411                     


In an interactive shell, name and args of the backgrounded command
are printed. These are missing in the case of the non-interactive shell.
Comment 1 Jonathan Chen freebsd_committer freebsd_triage 2001-09-03 00:16:45 UTC
State Changed
From-To: open->closed

If you want a shell that behaves the same way as an interactive shell, 
start sh with the -i flag. 

The reason this does not work in non-interactive mode is because the command 
string is not stored unless the shell is an interactive root shell. 
See jobs.c line 678: 
if (iflag && rootshell && n) 
ps->cmd = commandtext(n);