쉘 명령 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

명령을 실행한 후 !$키를 눌러 결과를 확인하세요 !$.

관련 정보