Back to Run a command with the argument from the last command。这篇文章解释了如何在新命令中使用以前的命令参数。
我的问题是如何在这些参数之间进行迭代?
例如:只是例子不需要这个
假设我创建了两个目录 dir1 和 dir2
mkdir dir1 dir2
Run Code Online (Sandbox Code Playgroud)
我想移动dir1
到dir2
无需再次重新输入参数。在处理复杂的参数或长路径时,这是非常少的。
需要最简单的命令
更新
假设我有一个命令
mkdir arg1 arg2 arg3 arg4 ... argn
Run Code Online (Sandbox Code Playgroud)
我想移动arg2
到argn
我发现了一些有趣的使用选项!
。
要获取上一个命令的参数,您可以使用:
!^ gives the first argument
!:n gives the nth argument
!* gives all the arguments
Run Code Online (Sandbox Code Playgroud)
所以在这种情况下
mkdir arg1 arg2 arg3 arg4 ... argn
Run Code Online (Sandbox Code Playgroud)
移动arg2
到arg5
例如使用:
mv !:2 !:5
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
174 次 |
最近记录: |