[root@localhost tmppcm]# ls ; echo exit code was: $? & echo pid is: $! test.txt .. .... ..... ...... lastfile.txt [1] 1265 pid is: 1265 exit code was: 0
In above it is as it runs ls to begin with, and then ends by running the echo's in 'parallel'.
Not quite what I want. I'd like that the sequence ls and echo exit code was: $? to be performed in the background, and echo process id in 'parallel'.
A solution could be to use || instead of ; between ls and echo exit code was:
[root@localhost tmppcm]# ls || echo exit code was: $? & echo pid is: $! [1] 1271 pid is: 1271 test.txt .. .... ..... ...... lastfile.txt exit code was: 0
Is there a more clever way to do this with the A ; B & C combination that I'm missing?
waitit might work for both jobspecs and pids, but there's a chance that command would only work from the prompt, and not within a script. See my question on SO about the difference between testing for a job to finish vs. a process to finsih--they are not identical