履歴拡張を使用した速記のクイック交換に問題がありますか?

履歴拡張を使用した速記のクイック交換に問題がありますか?

私のターミナル(bash 3)は時々速い交換を使用します。

^aa^bb^

^string1^string2^

         Quick substitution.  Repeat the last command, replacing string1 with string2.  Equivalent to `!!:s/string1/string2/` (see Modifiers below).

例えば

$ echo aa aa
aa aa
$ ^aa^bb^
echo bb aa
bb aa

これは、いくつかの状況では本当に便利かもしれません。

しかし、最後のものを省略しても^効果があることがわかりました。

$ echo aa aa
aa aa
$ ^aa^bb
echo bb aa
bb aa

私の質問は:最後の文を省略するとどのような結果になりますか^?安全に置いてもいいですか?それとも予防措置がありますか?

ベストアンサー1

イベントラインの最後の文字の場合は省略可能です。

まず、次の^string1^string2^意味を確認してくださいman bash

^string1^string2^
              Quick  substitution.   Repeat   the   previous   command,   
              replacing   string1   with   string2.    Equivalent   to
              ``!!:s/string1/string2/'' (see Modifiers below).

したがって、これはと同じですs/string1/string2/s修飾子に関するドキュメントをお読みください。

s/old/new/
          Substitute new for the first occurrence of old in the event line.  
          Any delimiter can be used in  place  of  /. The final  delimiter  
          is optional if it is the last character of the event line. The 
          delimiter may be quoted in old and new with a single backslash.  
          If & appears in new, it is replaced by old.  A single backslash 
          will quote the &. If old  is  null,  it is set to the last old 
          substituted, or, if no previous history substitutions took place, 
          the last string in a !?string[?]  search.

おすすめ記事