Piping jobs output
- Reply: Vlad Markov : "Re: Piping jobs output"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 12 Jan 2022 20:02:50 UTC
I have a number of shell scripts that scan various directories updating files. They can be quite time consuming so I put parts of the operations in the background and use "jobs" to manage how many things I put in the background. With bash this work beautifully but with FreeBSD's /bin/sh it's broken. So here's how I've been doing things: How I count the number of jobs I have in the background: jobs | wc -l In my scanning loop, to limit the jobs I create I have: while [ "$(jobs | wc -l)" -ge 4 ]; do sleep 2 done In /bin/sh the piping of jobs output doesn't seem to work. This lists all the jobs: jobs This always returns 0: jobs | wc -l The just returns an empty line: jobs | cat I don't know if I've stumbled on a bug or feature. I haven't seen anything that says I can't pipe the output of builtin commands in sh. This is on the lastest version FreeBSD 13. -- Ron Wills https://www.digitalcombine.ca Open Source & The Command Line