我怎样才能回忆起以前命令的参数? (在 csh 和 bash 中?)

how can I recall previous commands' arguments? (in csh, and in bash?)

我通常使用csh(实际上我的/bin/csh链接到tcsh,csh的改进版本)并且经常使用!$来引用最后一个命令的最后一个参数.
但有时我想使用上一个命令的最后 two 个参数。我怎样才能做到这一点?我想我可以访问任何先前命令的参数。

我已阅读 How can I recall the argument of the previous bash command? 但找不到答案。 我们如何引用前一个命令的倒数第二个参数?

例如,如果我给了echo tiger rabbit,我如何为下面的命令引用tiger? csh 的答案最好,但我也对 bash 案例感到好奇。

使用历史扩展你可以从 历史,按原样执行,或修改它并根据您的执行 需要。这 !开始历史扩展。

  • !! Repeats the previous command
  • !10 Repeat the 10th command from the history
  • !-2 Repeat the 2nd command (from the last) from the history
  • !string Repeat the command that starts with “string” from the history
  • !?string Repeat the command that contains the word “string” from the history
  • ^str1^str2^ Substitute str1 in the previous command with str2 and execute it
  • !!:$ Gets the last argument from the previous command.
  • !string:n Gets the nth argument from the command that starts with “string” from the history.

  • !^ first argument of the previous command

  • !$ last argument of the previous command
  • !* all arguments of the previous command
  • !:2 second argument of the previous command
  • !:2-3 second to third arguments of the previous command
  • !:2-$ second to last arguments of the previous command
  • !:2* second to last arguments of the previous command
  • !:2- second to next to last arguments of the previous command
  • !:0 the command itself

最后但同样重要的是,我还建议您按 Alt + . 以访问您之前输入的任何命令的最后一个参数