[Pdx-pm] solved: job control (still got a question)

Michael R. Wolf MichaelRunningWolf at att.net
Tue Jun 3 20:36:33 CDT 2003

Randall Hansen <randall at sonofhans.net> writes:

> Thus spoke "Michael R. Wolf" <MichaelRunningWolf at att.net>
> ( Tue, 03 Jun 2003 16:38:26 -0700 ):
>> >    PROMPT_COMMAND="PS1=\$(jobs | ~/bin/prompt_me.pl)"
>> Hey, foul! You lead us down (or we got faked down) a "do it in a
>> subshell" mindset. Just kiddin', though I think we all thought some
>> differnt, *normal*, calling sequence.
> I think you got faked, but not by me.  My original question was how to
> do this in Perl, and that "normal" method is still my preference.  Tom
> Phoenix suggested the pipe in one of the early replies and it's a nice
> solution -- and end-run around the problem.

It's not the pipe that did the end run, it's the 'jobs' run in the
current shell, thus avoiding the subshell problem. Of course, it does
join nicely to a pipe.

>> That's the only way I can think that this is working -- the command
>> substitution is not creating a subshell for evaluating 'jobs'.
> It's not even command substitition - the PROMPT_COMMAND line is in my
> .bashrc :)

As a ksh programmer, I'm unfamiliar with PROMPT_COMMAND, but since
$(...) is command substitution in ksh, I'd bet it means the same in

And there's some other 'eval' magic going on (as also hinted at by
Tom's original suggestion) with PS1 that doesn't go on with other

BTW -- I've loved the syntax of $(...) ever since it became the "new
command substitution" syntax in the mid-80's.  [Don't ever name
anything 'new'....]  

Most folks don't know it's the same as backticks, `...`. I find
backticks so hard to see, print, speak and direct someone else to
type. And they don't nest. And look at the parallelism:

 ${var} -- variable substitution
 $(cmd) -- command  substitution

I find that students in my classes understand variable substitution,
and the similarities make it easier to explain command substitution.
${var} accesses memory; $(var) accesses a process. The result from
either is substituted.

$ date="right now (as a string variable)"
$ print "At the tone, the time will be: ${date}"
At the tone, the time will be: right now (as a string variable)
$ print "At the tone, the time will be: $(date)"
At the tone, the time will be: Tue Jun  3 18:31:17 PDT 2003

Somehow, unifying the syntax helped me see the similarities in a way
that backticks never did.

Try this with backticks....

    nl $(grep -l play $(grep -l Wolf *)) | pr -h "${PWD} $(date)" | lpr

determine which files contain "Wolf"
of those, determine which files contain "play"
then number the file names,
page 'em with a header of here-and-now
and print the mini report

Michael R. Wolf
    All mammals learn by playing!
        MichaelRunningWolf at att.net

More information about the Pdx-pm-list mailing list