7

When i look at the jobs -x explanations, it says:

If the -x option is supplied, jobs replaces any jobspec found in command or arguments with the corresponding process group ID, and executes command, passing it arguments, returning its exit status.

Without an example, this explanation is extremely inadequate. If possible, can you give an example of the "x" option usage in real life? When do we need these options?

1 Answer 1

8

Example:

$ sleep 300 &
[1] 16012
$ echo %1
%1
$ jobs -x echo %1
16012

Here %1 is the jobspec. The number was taken from [1] shown just after the job was created. Without jobs -x %1 is just a string, so echo %1 prints the string. jobs -x replaces the jobspec with the corresponding process group ID before running echo.

If you want to do something to the process group, jobs -x is a way to substitute the right ID.

My tests indicate that if the job doesn't exist then %1 will stay literal and the command will be executed anyway. I have found no way to make jobs -x fail by itself in such case, so I think the command (or the whole script) should be ready to handle it somehow (e.g. to fail without making any damage).

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.