miwarin / netbsd-gnats-memo

0 stars 0 forks source link

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

Open miwarin opened 9 years ago

miwarin commented 9 years ago

http://gnats.netbsd.org/41836

%% の場合

#!/bin/sh

sleep 100 &
f=$(jobs -l %%)
echo "$f"

sh と zsh は何も表示されない

% /bin/sh a.sh

zsh

% /usr/pkg/bin/zsh a.sh

ksh と bash はジョブが表示される

% /bin/ksh a.sh
[1] +   451 Running              sleep 100

bash

% /usr/pkg/bin/bash a.sh
[1]+   136 実行中               sleep 100 &

%- の場合

#!/bin/sh

sleep 100 &
f=$(jobs -l %-)
echo "$f"

sh は PID がマイナス

% /bin/sh b.sh
[1] - 405 Running             sleep 100

bash は PID がプラス

% /usr/pkg/bin/bash b.sh
[1]+   827 実行中               sleep 100 &

ksh と zsh はジョブなし と言われる

% /bin/ksh b.sh
b.sh[4]: jobs: %-: no such job

zsh

% /usr/pkg/bin/zsh b.sh
b.sh:jobs:4: no previous job
miwarin commented 9 years ago

仕様

jobs

Both "%%" and "%+" are used to refer to the current job. Both forms are of equal validity-the "%%" mirroring "$$" and "%+" mirroring the output of jobs. Both forms reflect historical practice of the KornShell and the C shell with job control.