<div dir="ltr">A new trick I learned since the previous round (as far as I remember):<div><br></div><div>"jobs -x command which takes pid %" will pass the job's pid to the command, e.g.</div><div><br></div><div>
$ long running command &</div><div>[1] 52282</div><div>$ jobs -x watch pstree -pall %</div><div><br></div><div>Will pass "52282" to pstree.</div><div><br></div><div>You can stick any background job reference instead of just plain "%" (which refers to the "current default" background job), and of course you can stick multiple job references anywhere on the command line.</div>
<div><br></div><div>You can use the "jobs" on the same command line as the one when the background job is started:</div><div><br></div><div>$ find / > /dev/null 2>&1 & jobs -x watch pstree -pall %</div>
<div><br></div><div>This would give the same result as "$!" but more flexible about which background job is used, e.g. I commonly do:</div><div><br></div><div>$ command > /tmp/file 2>&1 & tail --pid $! -F /tmp/file</div>
<div><br></div><div>to watch a long running background process' output and keep its log output in a file. tail's "--pid" means that it'll exit when that pid terminates and Bash replaces the "$!" by the pid of the last started background job.</div>
<div><br></div><div>It's probably useful for bash functions/aliases (e.g. I'd like to alias the "tail" command above so I don't have to repeat the output file name in both the watched command and the tail), though I haven't got around to construct such an alias yet (submissions would be gladly accepted :) ).</div>
<div><br></div><div>--Amos</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 2 January 2014 07:19, Eli Billauer <span dir="ltr"><<a href="mailto:eli@billauer.co.il" target="_blank">eli@billauer.co.il</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div style="direction:ltr" bgcolor="#ffffff" text="#000000">
<p>Hello all,</p>
<p>On Monday (January 6th), Haifux will re-run its good old Schlager "Quick
and Dirty Bash". Anyone who wants to get a better grip on one-liners in
bash and some basic scripting, this is the place and time.</p>
<p>The slides are available at</p>
<p><a href="http://www.haifux.org/lectures/100-sil" target="_blank">http://www.haifux.org/lectures/100-sil</a></p>
<p>This is an extra announcement, as the lecture was added at short
notice.</p>
<p>See you,</p>
<p> Eli<span class="HOEnZb"><font color="#888888"><br>
</font></span></p><span class="HOEnZb"><font color="#888888">
<pre cols="72">--
Web: <a href="http://www.billauer.co.il" target="_blank">http://www.billauer.co.il</a>
</pre>
</font></span></div>
<br>_______________________________________________<br>
Linux-il mailing list<br>
<a href="mailto:Linux-il@cs.huji.ac.il">Linux-il@cs.huji.ac.il</a><br>
<a href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il" target="_blank">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">
<a href="http://www.linkedin.com/in/gliderflyer" target="_blank">
<span>
<img src="http://s4.licdn.com/scds/common/u/img/webpromo/btn_viewmy_160x25.png" alt="View my profile on LinkedIn" height="25" width="160">
</span></a></div>
</div>