어떻게합니까 !! bash에서 일합니까? 이전 명령의 별명처럼 작동합니다.

명령 시작 부분에서 sudo를 잊어 버렸을 때 매우 유용 !!하며 이전 명령의 별명처럼 작동합니다. 예 :

$ mv /very/long/path/for/a/protected/sensible/file/caution.h .
(...) Permission denined
$ sudo !!
sudo mv /very/long/path/for(...) .
[sudo] password :
  • 우리는 어떻게 더블 !!트릭 이라고 부릅 니까? 인터넷을 통한 연구는 그 토큰 때문에 어렵습니다.
  • 어떻게 작동합니까? history 명령과의 링크가 의심됩니다.
  • 어디에 정의되어 있습니까? 다른 것을 직접 정의 할 수 있습니까?

편집 : 흥미로운 이벤트 지정자

!!:*

이전 명령의 인수를 나타냅니다. 사용 사례 :

cat /a/file/to/read/with/long/path
nano !!:*

:p

명령을 실행하지 않고 인쇄하기 만하면 이벤트 지정자 끝에 놓아야합니다.

$ !-5:p
sudo rm /etc/fstab -f

더 여기에 .



답변

!!bash설명서의 “이벤트 지정자”제목 아래에 나열되어 있습니다.

   An event designator is a reference to a command line  entry  in  the
   history 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 posi-
          tion in the history list starting with string.
   !?string[?]
          Refer to the most recent command preceding the current  posi-
          tion  in  the history list containing string.  The trailing ?
          may be omitted if string is followed immediately  by  a  new-
          line.
   ^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.

따라서 !!이전 명령으로 대체됩니다.

쉘 히스토리에는 리터럴이 !!아니라 실행 된 실제 명령이 포함됩니다 .

$ ls
[some output]

$ !! .
[same output]

$ history 3
  645  2016-08-25 17:40:55 ls
  646  2016-08-25 17:40:57 ls .
  647  2016-08-25 17:41:00 history 3