Matt Wozniski wrote:
> On 3/8/07, Micah Cowan wrote:
>> Hello, all. This is my first post to this group.
>>
>> I scoured the manpages and list archives, but could not find the answer
>> I seek.
>>
>> My question, in a nutshell, is: How can I effectively use the "jobs"
>> builtin command in producing the interactive prompt?
>
> Rather than trying to parse the output of the 'jobs' command, you
> might find yourself better suited by manipulating the variables
> $jobdirs, $jobstates, and $jobtexts. You correctly identified the
> problem that you're hitting - $(jobs) is running in a subshell that
> doesn't have any jobs in its job table. I agree, however, that (jobs)
> should also be blank, since it's also running in a subshell. If,
> however, you're dead-set on parsing the output of 'jobs', you could
> use a syntax like 'jobs > >(read jobtext; echo $jobtext)', which is a
> clever way to run jobs in the current shell and do the parsing in a
> subshell via process substitution.
Myself, I'd prefer to see both subshells produce the same output as the
"current shell", as bash, pdksh and ksh do. However, dash goes the other
way and makes ( jobs ) emit nothing (for all its claims of being a POSIX
shell, though, dash is fairly broken in some respects, such as broken
arithmetic expansion and lack of a line-editor [which POSIX requires]).
I'd be interested in seeing what the OpenGroup committee has to say
about it, since the standard is far from clear on the subject.
I was not familiar with the variables you mention above. However, I'm
not sure they solve the problem, as yet again, invoking them within a
command-substitution will produce no information. The same problem would
be true of using the other syntax you describe: I still have no
available means to run the commands every time the prompt is issued,
apart from within command substitution, which will kill the job-state
info. Is there any way to get what I want executing in the "current" shell?
Also, had you meant to post this reply to the list? It appears to have
been sent to me only.