
터미널에서 이와 같은 명령을 실행하면
$ tyop --count 3 --exact haveibeenpwned
이 명령은 다음과 같은 오류 코드를 반환합니다.
command not found: tyop
,
명령줄 인수를 --count 3 --exact haveibeenpwned
다른 명령 이름(예: typo
대신 tyop
)으로 유지하면서 마지막 명령을 다시 실행하려면 어떻게 해야 합니까?
$ typo --count 3 --exact haveibeenpwned
!!
가능하다면 또는 와 같은 단축키나 쉘 기능을 찾고 있습니다 !^
.
답변1
typo !*
~에서man bash
:
Word Designators
Word designators are used to select desired words from the event. A :
separates the event specification from the word designator. It may be
omitted if the word designator begins with a ^, $, *, -, or %. Words
are numbered from the beginning of the line, with the first word being
denoted by 0 (zero). Words are inserted into the current line
separated by single spaces.
* All of the words but the zeroth. This is a synonym for `1-$'.
It is not an error to use * if there is just one word in the
event; the empty string is returned in that case.
답변2
위쪽 화살표를 누르고 입력 줄을 수동으로 편집하는 것과 같은 명백한 것 외에도GNU 읽기 라인(및 기타 여러 프로그램에서 사용됨 bash
)에는 몇 가지 유용한 기록 편집 기능이 내장되어 있습니다. !*
다른 답변에서 언급했듯이 그것은 그중 하나입니다.
또 다른 방법은 문자열 교체 기능을 사용하는 것입니다 ^
. 에서 man bash
:
^string1^string2^
빠른 교체. 이전 명령을 반복하여 string1을
string2로 바꿉니다. (아래 수정자 참조) 와 동일합니다!!:s^string1^string2^
.
^tyop^typo^
이 기능을 사용하면 Enter를 입력하고 눌러 명령을 수정할 수 있습니다.
Bash의 역사를 통해 할 수 있는 일이 훨씬 더 많습니다. 실행 man bash
하고 검색하여 HISTORY EXPANSION
이 섹션과 모든 하위 섹션( Event Designators
, Word Designators
및 Modifiers
)을 읽어보세요.
그건 그렇고, 제목이 붙은 섹션을 읽 READLINE
거나 적어도 그것이 무엇을하는지 대략적인 아이디어를 얻기 위해 훑어 보는 것도 가치가 있습니다. readline에 대한 전체 문서는 다음에서 찾을 수 있습니다.https://tiswww.cwru.edu/php/chet/readline/rltop.html그리고https://tiswww.cwru.edu/php/chet/readline/readline.html
답변3
이 !$
변수는 이전 명령의 마지막 매개변수를 저장합니다.
예:
touch hello
cat !$ #equivalent to "cat hello"
!*
$_
모든 매개변수를 저장합니다 .
자세한 내용과 대체 명령이 포함된 비슷한 질문여기