NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/41836: jobs -l %% doesn't work when called from a script



>Number:         41836
>Category:       bin
>Synopsis:       jobs -l %% doesn't work when called from a script
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Aug 07 07:50:00 +0000 2009
>Originator:     Stathis Kamperis
>Release:        NetBSD 5.0_STABLE
>Organization:
Aristotle University of Thessaloniki
>Environment:
[stathis@voyager ~] uname -a
NetBSD voyager 5.0_STABLE NetBSD 5.0_STABLE (MYGENERIC) #9: Wed Aug  5 00:38:20 
EEST 2009  root@voyager:/usr/obj/sys/arch/i386/compile/MYGENERIC i386

>Description:
jobs -l %%     and    jobs -l %+ don't work when they are used inside a script.
Whereas they work when invoked by an interactive shell.
>How-To-Repeat:
INTERACTIVE SHELL
-----------------
[stathis@voyager ~] sleep 100 &
[1] 22149
[stathis@voyager ~] jobs -l %%
[1]+ 22149 Running                 sleep 100 &
[stathis@voyager ~] jobs -l %+
[1]+ 22149 Running                 sleep 100 &
[stathis@voyager ~]

SCRIPT
------
[stathis@voyager ~] cat lala.sh
#!/bin/sh

sleep 100 &
f=$(jobs -l %%)
echo "$f"
[stathis@voyager ~] ./lala.sh
                               <---- an empty line is printed
[stathis@voyager ~] 

Same applies to $(jobs -l %+).

What is interesting is that... if you put %- (which denotes the previous job), 
the scripts outputs the sleep job.

[stathis@voyager ~] cat lala.sh
#!/bin/sh

sleep 100 &
f=$(jobs -l %-)
echo "$f"
[stathis@voyager ~] ./lala.sh
[1] - 12972 Running           sleep 100          <---- there shouldn't be a 
'minus' sign here. This should be '+', since sleep is the only and current job.
[stathis@voyager ~]


Linux, Solaris 10 and DragonFlyBSD get it right (%% and %+ list the sleep job).
>Fix:



Home | Main Index | Thread Index | Old Index