Linuxには、最後に入力したsudo !!
コマンドに文字通り適用されるコマンドがあることを知りましたsudo
。私はそれについて聞いたことがありませんでした。
それは一般的なコントロールですか?それに関するドキュメントはどこで入手できますか?
Linuxには、最後に入力したsudo !!
コマンドに文字通り適用されるコマンドがあることを知りましたsudo
。私はそれについて聞いたことがありませんでした。
それは一般的なコントロールですか?それに関するドキュメントはどこで入手できますか?
回答:
これは単なるbashショートカットです。sudo!!
ちなみに、そうではありません。それはですsudo !!
(スペースに注意します)。
!!
bashでは、基本的には前のコマンドの拡張です。
bashのmanページの「History Expansion」セクションを見てください。
http://www.gnu.org/software/bash/manual/bashref.html#Event-Designators
これは、実際のですsudo !!
コマンドで構成され、sudo
あなたはおそらく馴染みのある、そしてイベントの指示、!!
入力された最後のコマンドを指し、。詳細についてはbash
、Event Designators
セクションの下のマニュアルページを参照してください。
Event Designators
An event designator is a reference to a command line entry in the his‐
tory list. Unless the reference is absolute, events are relative to
the current position in the history list.
! Start a history substitution, except when followed by a blank,
newline, carriage return, = or ( (when the extglob shell option
is enabled using the shopt builtin).
!n Refer to command line n.
!-n Refer to the current command minus n.
!! Refer to the previous command. This is a synonym for `!-1'.
!string
Refer to the most recent command preceding the current position
in the history list starting with string.
!?string[?]
Refer to the most recent command preceding the current postition
in the history list containing string. The trailing ? may be
omitted if string is followed immediately by a newline.
^string1^string2^
Quick substitution. Repeat the previous command, replacing
string1 with string2. Equivalent to ``!!:s/string1/string2/''
(see Modifiers below).
!# The entire command line typed so far.
この機能の分離は、最も美しい設計原則の1つであり、Linux / Unixを他の選択肢よりも強力にします。各プログラムは、独立した独立した規約と機能の島です。
「各プログラムに1つのことをさせ、それをうまくやらせる」
実装するのではなく!! sudo(または他のコマンド)内で、前のコマンドを繰り返すことで恩恵を受けることができます。これは1回(シェルで)実装され、すべてのコマンドが恩恵を受けます。だからあなたができる:
$ echo !! # will echo the last command
$ time !! # will repeat and time the last command
$ strace !! # will repeat the last program while system-call tracing it
等々。
しかし、それで終わりではありません。シェルは、!を介して履歴を拡張するだけではありません。イベント指定子。コマンドを実行する前に、変数展開、ファイル名ワイルドカード展開(グロビング)、コマンド置換、ファイル/ IOリダイレクトなどを実行します。これらはすべて、シェルから呼び出されるコマンドで活用および使用できます。
もう1つの大きな利点は、シェル(この場合は「man bash」)の学習に時間をかける場合、一度学習する必要があり、これらの強力な機能をいつでもどこでも使用できることです。コマンドラインagrが各プログラムまたはユーティリティでどのように処理されるかを再学習するよりも、強力な原則と規則の1つのセットを学ぶ方がはるかに簡単です。