问题
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