Bash

如何為 Readline 函式提供數字參數,例如“glob-expand-word”?

  • June 20, 2020

如何為 Readline 函式提供參數,例如預設glob-expand-word綁定的參數?C-x *

在這種情況下,我想提供一個數字參數來使游標前的單詞附加一個星號。

man bash:

全域擴展字 (Cx *)

point 之前的單詞被視為路徑名擴展的模式,並插入匹配的文件名列表,替換單詞。如果提供了數字參數,則在路徑名擴展之前附加一個星號。

可以使用 將數字參數提供給 Readline 函式M-0, M-1,...,其中M--以負數字參數開頭。

此外,universal-argument可選綁定到C-u(見下文)的函式還可以通過執行函式然後按下一系列數字(可選地帶有前導減號)向命令提供數字參數:

         "\C-u": universal-argument

man bash(摘錄)

  Numeric Arguments
      digit-argument (M-0, M-1, ..., M--)
             Add this digit to the argument already accumulating, or start a new argument.  M-- starts a negative argument.
      universal-argument
             This is another way to specify an argument.  If this command is followed by one or more digits, optionally with a leading minus sign, those digits define the argument.  If the command is  followed  by
             digits,  executing  universal-argument again ends the numeric argument, but is otherwise ignored.  As a special case, if this command is immediately followed by a character that is neither a digit nor
             minus sign, the argument count for the next command is multiplied by four.  The argument count is initially one, so executing this function the first time makes the argument count four, a second  time
             makes the argument count sixteen, and so on.

引用自:https://unix.stackexchange.com/questions/594019