Misleading phrasing about $! in documentation

2013-07-31 Thread Chris Down
I think our documentation on $! is a little misleading. `man bash' states:

Special Parameters
The shell treats several parameters specially. These parameters may only
be referenced; assignment to them is not allowed.

[...]

! Expands to the process ID of the most recently executed background
(asynchronous) command.

I don't think this statement is true. Take this as an example:

$ sleep 60
^Z
[1]+  Stopped sleep 60
$ sleep 60 &
[2] 6580
$ bg
[1]+ sleep 60 &
$ echo "$!"
6579

The pipeline with the PID referenced by $! was not executed last, it was merely
backgrounded last. I suggest s/executed background/backgrounded/.

If this is accepted as valid, I will happily write and attach a patch.

Best,

Chris


pgpUkRpRHbYxG.pgp
Description: PGP signature


feature request: capture output of last command and make it available on some hotkey

2013-07-31 Thread Jörn Hees
Hi,

i think this would be a very useful feature and i don't seem to be alone:
http://stackoverflow.com/questions/5955577/bash-automatically-capture-output-of-last-executed-command-into-a-variable
http://unix.stackexchange.com/questions/9024/how-do-i-reuse-the-last-output-from-the-command-line

There are a lot of hackish solutions how you could achieve this, but since 
readline actually provides the yank-last-arg it would somehow be cool to also 
have a yank-last-output-line, maybe on M-, instead of M-.

As outputs might get pretty big, maybe bash could remember up to the the first 
and last 10 lines of output of the previous command. After that counting 
usually gets slower than using another approach anyhow.

Use cases:
- type some command, realize you want to do something with the last line of the 
output, for example view the path written there, type "less ", hit [esc] [,], 
done…
- whenever you used your mouse to copy that one line from the last output just 
to reinsert it after the command you just typed.

Cheers,
Jörn




Re: feature request: capture output of last command and make it available on some hotkey

2013-07-31 Thread Greg Wooledge
On Wed, Jul 31, 2013 at 02:09:23AM +0200, Jörn Hees wrote:
> i think this would be a very useful feature and i don't seem to be alone:
> http://stackoverflow.com/questions/5955577/bash-automatically-capture-output-of-last-executed-command-into-a-variable

Bash has no knowledge of, and no way to interact with, commands that
it spawns.

When bash runs a command (e.g. "cat file"), bash merely makes sure that
stdout and the other file descriptors are properly aligned, and then
calls exec().  It is the command itself (cat) which actually does the
writing, and it writes directly to the terminal, or the pipeline, or
wherever stdout is set to go.

Bash can't "capture" this in a variable.  Your TERMINAL might be able to
cough up output on demand, but bash is completely unaware of the output.