bash bang(!)とレコードを使用してパラメータを交換/変更することは可能ですか?

bash bang(!)とレコードを使用してパラメータを交換/変更することは可能ですか?

私は現在引くLinuxの機能を上回り、historyそれに!基づいて構築されました。bash

私は!!同じ関数を使用することに慣れています!:<argc>が、たとえば、間違ったパラメータを以前に追加して間違えた場合は、その間違ったパラメータを削除してコマンドラインを再利用する方法はありますか?

はい

次のエラーが発生した場合:

      mv -r movableFolder/ targetFolder/

-rオプションがないので、いくつかのトリックを使ってそれを削除したいとmv思います。!

      mv movableFolder/ targetFolder/

上記の履歴コマンドで次のことができることがわかります。

     mv !:2 !:3

しかし、代わりにコマンドをmv使用する方法はありますか?!

ベストアンサー1

これにより、次の例に示すように、パラメータ2と3の使用を簡素化できます。

$ echo -r movableFolder/ targetFolder/
-r movableFolder/ targetFolder/

$ echo !:2*
movableFolder/ targetFolder/

すべてはman bashに文書化されています:

単語の表示 単語の表示は、イベントで目的の単語を選択するために使用されます。 A:イベント仕様を単語指定子から分離してください。 ^、$、*、-、%で始まる単語の表示は省略できます。単語は行の先頭から番号が付けられ、最初の単語は0(ゼロ)で表されます。単語は単一のスペースで区切られ、現在の行に挿入されます。

  0 (zero)  The zeroth word.  For the shell, this is the command word.
  n         The nth word.
  ^         The first argument. That is, word 1.
  $         The last word. This is usually the last argument, but will
            expand to the zeroth word if there is only one word in the line.
  %         The word matched by the most recent `?string?' search.
  x-y       A range of words; `-y' abbreviates `0-y'.
  *         All  of the words but the zeroth. This is a synonym for `1-$'.
            It is not an error to use * if there is just one word in the event;
            the empty string is returned in that case.
  x*        Abbreviates x-$.
  x-        Abbreviates x-$ like x*, but omits the last word.

イベントを指定せずにワード指定子が指定された場合、前のコマンドがイベントとして使用されます。

したがって、この行を使用した後:

$ echo -r movableFolder/ targetFolder/
echo -r movableFolder/ targetFolder/

これは働きます:

$ !:0 !:2*
movableFolder/ targetFolder/

これ:

$ !:0 !:2-$
movableFolder/ targetFolder/

おすすめ記事