シェルコマンド cd !$

シェルコマンド cd !$

私が探していますこの問題検索しましたが、明確な回答が見つかりませんでした。!$端末に入力するとどうなりますか?

私は入った

mkdir /path/to/dir
cd !$

これが考えられました。しかし、まだ交換員が一般的に何をしているのかを/path/to/dir正確に知りたいです。!$

ベストアンサー1

Bashマニュアル>履歴拡張から:

  • イベントインジケータ

    !      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.
    
  • 単語インジケーター

    $      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.
    

だから、!$前のコマンドの最後の単語を繰り返してください。

例:

$ echo Unix and Linux
Unix and Linux
$ echo !$
echo Linux
Linux

$ cat dir1
cat: dir1: Is a directory
$ cd !$
cd dir1

コマンドを実行したら、!$キーを押して結果を確認します!$

おすすめ記事