且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

BASH - 如何使用从previous命令参数?

更新时间:2023-12-05 19:13:22

正如 M - (元点或ESC点或ALT点)是readline的功能抽出,最后ARG MCY (元控制y或ESC-CTRL-Y或CTRL- ALT-y)是readline的功能抽出,第n-ARG 。如果不指定 N ,却是拷贝一previous命令的第一个参数。

Just as M-. (meta-dot or esc-dot or alt-dot) is the readline function yank-last-arg, M-C-y (meta-control-y or esc-ctrl-y or ctrl-alt-y) is the readline function yank-nth-arg. Without specifying n, it yanks the first argument of the previous command.

要指定参数,preSS逃亡的数字或按住Alt键并preSS的数字。你可以做替代骨节病> - - 骨节病>开始指定然后负数松开Alt键和preSS数字(这将计算从参数列表的末尾

To specify an argument, press Escape and a number or hold Alt and press a number. You can do Alt--to begin specifying a negative number then release Alt and press the digit (this will count from the end of the list of arguments.

例如:

输入以下命令

$ echo a b c d e f g
a b c d e f g

现在在下一个提示符下,键入回声(有以下空间),那么

Now at the next prompt, type echo (with a following space), then

preSS 替代骨节病> - 控制骨节病> - 是骨节病>,现在您将看到:

Press Alt-Ctrl-y and you'll now see:

$ echo a

无pressing 输入骨节病>然而,请执行以下操作

preSS 替代骨节病> - 3 骨节病> 替代骨节病> - 控制骨节病> - 是骨节病>

Press Alt-3 Alt-Ctrl-y

preSS 替代骨节病> - - 骨节病> 2 骨节病> 替代骨节病> - 控制骨节病> - 是骨节病>

Press Alt-- 2 Alt-Ctrl-y

现在您将看到:

$ echo ace

顺便说一句,你可能会选择把回声就行参数0:

preSS 替代骨节病> - 0 骨节病> 替代骨节病> - 控制骨节病> - 是骨节病>

Press Alt-0 Alt-Ctrl-y

编辑:

要回答你添加到你原来的问题:

To answer the question you added to your original:

您可以preSS 替代骨节病> - 0 骨节病>然后反复preSS 替代骨节病> - 以通过previous命令步骤(ARG 0)。同样替代骨节病> - - 骨节病>然后重复替代骨节病> - 骨节病>将允许您以逐步previous下一页 - 。到最后一个参数。

You can press Alt-0 then repeatedly press Alt-. to step through the previous commands (arg 0). Similarly Alt-- then repeating Alt-. would allow you to step through the previous next-to-last arguments.

如果有在历史上在特定线路没有适当的参数,钟会响。

If there is no appropriate argument on a particular line in history, the bell will be rung.

如果有您经常使用的特定组合,可以定义一个宏这样一个按键将执行它。这个例子会记得从previous命令由pressing第二个参数替代骨节病> - 移骨节病> - 是骨节病>。您可以***选择preFER,而不是这一个任何可用的按键。您可以preSS反复按步previous的。

If there is a particular combination you use frequently, you can define a macro so one keystroke will perform it. This example will recall the second argument from previous commands by pressing Alt-Shift-Y. You could choose any available keystroke you prefer instead of this one. You can press it repeatedly to step through previous ones.

要尝试一下,在Bash提示符输入宏:

To try it out, enter the macro at a Bash prompt:

bind '"\eY": "\e2\e."'

要使它持久的,这行添加到您的〜/ .inputrc文件文件:

To make it persistent, add this line to your ~/.inputrc file:

"\eY": "\e2\e."

不幸的是,这似乎并没有给ARG 0或负值的参数号工作。

Unfortunately, this doesn't seem to work for arg 0 or negative argument numbers.