[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: process substitution in PROMPT_COMMAND
From: |
Chet Ramey |
Subject: |
Re: process substitution in PROMPT_COMMAND |
Date: |
Sun, 07 Aug 2011 18:28:38 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11 |
On 8/7/11 6:00 PM, Curtis Doty wrote:
> I've recently refactored my PROMPT_COMMAND function to avoid superfluous
> fork()s. In the body of the function, what was once this line:
>
> local jobcount=$(jobs |wc -l)
>
> is now this:
>
> local job jobcount=0
> while read job
> do ((jobcount++))
> done < <(jobs)
As you suspect, the problem is with this part of the function. It doesn't
really have anything to do with PROMPT_COMMAND, though. You must be
exporting the function so your PROMPT_COMMAND will work in interactive
subshells, and the problem is there.
>
> This works fine on bash 4. However, when attempting to use this on an older
> bash 3.00.15(1) host, an error occurs; but only on 2nd or additional
> subshells--not the first login shell!?! I.e. everything works fine, until I
> run bash from bash.
>
> bash: foo: line 39: syntax error near unexpected token `('
> bash: foo: line 39: ` done <<(jobs);'
> bash: error importing function definition for `foo'
>
> Am I missing a finer point of redirection from a substituted process? Or is
> something different in bash 3 that I need to work around here?
One of the bugs fixed between bash-3.1 and bash-3.2 concerned formatting
problems with redirections and process substitution -- the construct you
used. That code is used to decompose functions to pass them through the
environment, and the incorrectly-formed function has a syntax error that
prevents it being imported by the subshell.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU address@hidden http://cnswww.cns.cwru.edu/~chet/