Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 2
    Thank you merging these commands with "&" helped me a lot. Commented Nov 27, 2010 at 12:09
  • 12
    in a bash script, in a loop which starts programs, $! is not accurate. Sometimes it returns pid of the script itself, sometimes of grep or awk run from the script any solution to specifically get the pid of the process just launched in this scenario? something like pid=myprogram would have been awesome Commented Apr 26, 2014 at 5:59
  • 4
    NB that this requires you to start the command using a & as the previous line, otherwise the echo basically returns blank. Commented Feb 4, 2015 at 18:56
  • 3
    assigning to variable like command & echo $! freezes the execution at this step :( Commented Jul 15, 2016 at 9:41
  • This doesn't work if you don't explicitly background the process! For instance, your process may background itself after it has done something you need to wait for before continuing. Commented Apr 16, 2020 at 0:10