From 5c3513676757a7a9190f9ce56f5fcb34411e9c8b Mon Sep 17 00:00:00 2001 From: "Cristian A. Ontivero" Date: Fri, 28 Dec 2018 23:39:14 -0300 Subject: [PATCH] Added explanation for jobs flags (issue #1429), with some portable alternatives --- SC2039.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SC2039.md b/SC2039.md index cb7eb95..8b943a2 100644 --- a/SC2039.md +++ b/SC2039.md @@ -207,6 +207,16 @@ reuse_quote()( reuse_quote "$@" ``` + +### `jobs` flags + +The only acceptable flags under POSIX sh for `jobs` are `-l` and `-p` ([see spec](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/jobs.html)). Common flags supported by other shells are `-s` and `-r`, to check for stopped/suspended jobs and running jobs. A portable alternative is using `grep` or `awk`: +```sh +"$(jobs | awk '/(S|s)(topped|uspended)/')" # instead of jobs -s +"$(jobs | awk '/(R|r)(unning)/')" # instead of jobs -r +``` +Although the state of stopped jobs is `Stopped` in Bash and dash, and it's the one specified by POSIX, `Suspended` is also a valid alternative (but Zsh happens to not respect the capitalization, that's why we try to match `suspended`). Similarly, the state of running jobs is `Running` according to POSIX. Bash and dash respect this, but Zsh uses `running`. + ## Exception Depends on what your expected POSIX shell providers would use. \ No newline at end of file