LoginSignup
13
15

More than 5 years have passed since last update.

linux (bash?) > !$の使い方 (ついでに !^ と !:2 も)

Last updated at Posted at 2015-01-09

CentOS6.5にてbashシェルにて確認。

!$というのは前に使ったコマンドの最後の文字列を表す。

$ touch a b c d e
$ echo !$

とするとeが表示される。

$ mkdir SAMPLE_DIRECTORY_HOGEHOGE
$ cd !$

とするとSAMPLE_DIRECTORY_HOGEHOGEに移動できる。タブ補間入力よりも早い時もある。



(追記)

!$は直前のコマンドの「最後の文字列」のようですが、同じように!^は直前のコマンドの「最初の文字列」となるようです。

また、!:2のようにすると2つ目の文字列というように位置の指定もできるようです。

例として

  $ echo a b c d e
  $ echo !^ !:2 !:3 !$

とすると

  a b c e

という結果となります。

13
15
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
15