简体   繁体   中英

execute last output line of previous command in linux

How to execute last output line of previous command in linux bash terminal by shortcut?

For example:

$ tree 
The 'tree' is currently not installed. You can install it by running: 
sudo apt-get install tree

I want to copy for execution sudo apt-get install tree

If the last line is safe for running, a simple command, and contains no spaces or quotes or anything else the shell would need to parse/understand then this should work (though you need to re-run the first command for this).

$(!! 2>&1 | tail -n 1)

That being said I don't recommend this at all. It is much simpler (and safer and supports more complex commands) if you copy and paste or type it out again.

You cannot get the last line of displayed output though so you do need to re-run the command.

Your terminal might support shortcuts to let you copy and paste text though. GNU screen can do this. I believe rxvt-unicode might support this with perl scripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM