shell, job control for receiving end of the pipe

423 Views Asked by At

I don't understood, why I can't run some process ("cat" in this example) in background and later make it foreground:

$ dash
$ f() { cat </dev/stdin > /dev/stdout &  sleep 1; fg ; }
$ sleep 2 | f
dash: 1: fg: job (null) not created under job control
$ set -m 
$ sleep 2 | f
dash: 1: fg: job (null) not created under job control
$ f() { set -m; cat </dev/stdin > /dev/stdout &  sleep 1; fg ; }
$ sleep 2 | f
dash: 5: fg: job (null) not created under job control

Why every time I'm getting error message?

At some time I have no such messages when running function "f" without pipe:

$ set +m
$ f
cat 0</dev/stdin 1>/dev/stdout
^C
$ set -m
$ f
cat 0</dev/stdin 1>/dev/stdout
^C
0

There are 0 best solutions below