Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jobs has a different return code if used in a pipeline #2505

Closed
Lucretiel opened this issue Oct 26, 2015 · 3 comments
Closed

jobs has a different return code if used in a pipeline #2505

Lucretiel opened this issue Oct 26, 2015 · 3 comments
Milestone

Comments

@Lucretiel
Copy link
Contributor

While trying to write a simple wait command, I discovered that jobs behaves differently in a redirection or pipeline:

$ sleep 10 &
$ sleep 10 &
$ jobs
Job     Group   CPU     State   Command
2       ...     0%      running sleep 10 &
1       ...     0%      running sleep 10 &
$ jobs | cat
2       ...     0%      running sleep 10 &
1       ...     0%      running sleep 10 &

This makes perfect sense to me- many shell utilities have this behavior. However, jobs ALSO changes the return code if it is used in a pipeline:

$jobs; echo $status
jobs: There are no jobs
1
$ jobs > /dev/null; echo $status
0

This means that the following simple wait implementation doesn't work:

function wait
    while jobs > /dev/null
        sleep 0.1
    end
end

jobs should be changed to behave like count, set -q, etc. to return an error code if 0 jobs were found.

@maxnordlund
Copy link
Contributor

I've encountered the same issue, but I'm not sure if it should return 0 when jobs are found. It makes more sense how it is now with it returning 0 if there are jobs to report on, e.g. jobs --pid.

maxnordlund added a commit to maxnordlund/fish-shell that referenced this issue Nov 25, 2015
ridiculousfish pushed a commit that referenced this issue Dec 4, 2015
@maxnordlund
Copy link
Contributor

This should be resolved by the above commits, close this?

@ridiculousfish
Copy link
Member

Thanks!

@zanchey zanchey added this to the 2.3.0 milestone Mar 23, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants