So I'm doing some basic job control in a script and noticed that what I'm trying to do doesn't work in sh/dash (I'm on Ubuntu so sh is dash).
bash
$ jobs -p 3053 9202 $ jobs -p | wc -l 2 $ jobs -p | grep ".*" 3053 9202 $
sh/dash
$ jobs -p 9942 9940 $ jobs -p | wc -l 0 $ jobs -p | grep ".*" $ ls -l | wc -l 13 $ jobs -p > jobs.txt $ cat jobs.txt 9942 9940
Anyone have any idea what's going on here? Seems like the jobs built-in is going to stdout, but for some reason doesn't make it to stdin of wc or grep?
Edit: found a mailing list thread about this: https://www.spinics.net/lists/dash/msg01165.html
Edit 2: Can't find a good workaround for this and the Debian bug report for it has been open for nine years. In the words of the person who started that mailing list thread, "To me, 'just use $!' sounds to me a lot more like 'just go use another shell'" so I'm just going to use bash. Good work Debian team.
[link] [comments]