GNU Readlineのshell-expand-lineコマンドがチルダ(〜)の最初のエントリだけを拡張するのはなぜですか?

GNU Readlineのshell-expand-lineコマンドがチルダ(〜)の最初のエントリだけを拡張するのはなぜですか?

Bashのマニュアルによると、shell-expand-lineGNU Readlineコマンドは、Bashが通常行うように、エイリアスと履歴の拡張を含むコマンドラインを拡張する必要があります。

現在の設定は次のように表示されますbind -P | grep shell-expand-line

shell-expand-line can be found on "\e\C-e".

~私の問題は、次の例では最初のチルダ()のみが拡張されることです。

~/foo/bar ~/foo/baz

「\e\Ce」を押した後:

/Users/nlykkei/foo/bar ~/foo/baz

なぜ?

ベストアンサー1

見たらソースコードshell-expand-line、実際に呼び出す必要があることがわかりますshell-expand-line-as-if-it-were-a-word

>> bashline.c
static int
shell_expand_line (count, ignore)
     int count, ignore;
{
     ...
      w->word = savestring (rl_line_buffer);
      w->flags = rl_explicit_arg ? (W_NOPROCSUB|W_NOCOMSUB) : 0;
      expanded_string = expand_word (w, rl_explicit_arg ? Q_HERE_DOCUMENT : 0);
>>> subst.c
/* Expand WORD, performing word splitting on the result.  This does
   parameter expansion, command substitution, arithmetic expansion,
   word splitting, and quote removal. */

WORD_LIST *
expand_word (word, quoted)
     WORD_DESC *word;
     int quoted;

このコメントにはファイル名やチルダ拡張子は含まれません。したがって、基本的に最初のチルダにも機能するのは偶然です(チルダはとにかく単語の始めにのみ意味があります)。ただし、これは言及されていないプロセスの交換になります。重い操作はexpand_word_internal同じファイルの機能にあります。

最初のスニペットで言うのは、rl_explicit_argバインドされたキーの組み合わせの前にEsc-1またはAlt-2を押すとshell-expand-line引用符が削除されないことです。そしてプロセス/コマンド置換が実行されます。かなり直感的ではないですか?

バグレポートを送信することもできますが、Bashにはすでに同様の制限事項と特別なケースが数千ある可能性があります。

おすすめ記事