[Linux-disciples] Neat shell trick

Stephen R Laniel steve at laniels.org
Mon Jun 13 09:11:38 EDT 2005


http://necrotic.deadbeast.net/~branden/blog/exuberance/Debian/stupid_shell_tricks_01.html

Sun, 12 Jun 2005
Stupid Shell Tricks

I'm probably the only person who ever thinks like this, but
what the heck.

I recently found myself thinking (itself a noteworthy
occurrence)...I've started a what turns out to be a
long-running process at a shell prompt and I don't want to
visually monitor it. It didn't occur to me that it would
take a long time when I started it, and it would be nice to
have audio notification of its completion. The problem is,
it's already running.

Of course if you knew it was going to take a long time when
you started, you could have done something like this:
long-running-process && xmms $HOME/music/song.ogg. Let's say
you didn't exhibit that much foresight.

Traditional Unix process management primitives exposed via
the shell come to the rescue.

$ long-running-process

Damn, this is taking a while...

<CTRL-Z>

[1]+  Stopped                 long-running-process
$ bg
[1]+ long-running-process &
$ wait %1 && xmms $HOME/music/song.ogg

Voilà; I can go back to occupying myself, and when the music
starts up, I know my job is done — and I didn't have to kill
it and start it over. Once in a while, that's an important
consideration.

By the way, if you try to wait on a stopped job, you're
helpfully told how lame you are:

-bash: warning: wait_for_job: job 1 is stopped

...and the music starts to play even though your job isn't
finished. So don't forget to background it first. :)

Futhermore, this usage of wait appears to be standard. In
Debian, both bash and ash (a.k.a. dash) support both process
IDs and job IDs as operands to wait. zsh probably supports
identifying the job by its mother's maiden name as well, but
I haven't tried that.

-- 
Stephen R. Laniel
steve at laniels.org
+(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20050613/7ea756c8/attachment.pgp


More information about the Linux-disciples mailing list