How can you access the second argument of the second to last command at the cli?

旧街凉风 提交于 2019-12-11 07:33:03

问题


For example:

~ echo foo bar baz 
foo bar baz
~ echo catz ratz batz
catz ratz batz
~ echo !!:2 #=> ratz

In this case the !!:2 accesses the second argument of the last command. Is it possible to get the second argument of the second to last command which in this case would expand to bar?


回答1:


As illustrated by @Jahid in a previous post:

Second argument of the second to last command:

~ $ echo foo bar baz # This one is the target
foo bar baz
~ $ echo catz ratz batz
catz ratz batz
~ $ echo !-2:2
echo bar
bar

!-n expands to the command that was 'n' number of commands before the current command.

Note: !-1 and !! are the same



来源:https://stackoverflow.com/questions/37282078/how-can-you-access-the-second-argument-of-the-second-to-last-command-at-the-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!