![키 바인딩을 사용하여 bash 구성을 다시 가져올 때 "명령을 찾을 수 없음" 오류를 방지하는 방법은 무엇입니까?](https://linux55.com/image/113219/%ED%82%A4%20%EB%B0%94%EC%9D%B8%EB%94%A9%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20bash%20%EA%B5%AC%EC%84%B1%EC%9D%84%20%EB%8B%A4%EC%8B%9C%20%EA%B0%80%EC%A0%B8%EC%98%AC%20%EB%95%8C%20%22%EB%AA%85%EB%A0%B9%EC%9D%84%20%EC%B0%BE%EC%9D%84%20%EC%88%98%20%EC%97%86%EC%9D%8C%22%20%EC%98%A4%EB%A5%98%EB%A5%BC%20%EB%B0%A9%EC%A7%80%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
내가 사용하는 bash
버전 4.3.48
:
$ bash --version
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
C-x r
구성을 다시 로드하기 위해 키 시퀀스를 사용하여 키 바인딩을 정의하려고 합니다 bash + readline
.@Gilles님 감사합니다, 내 코드에 다음 코드를 포함합니다 ~/.bashrc
.
bind '"\e[99i~": re-read-init-file'
bind -x '"\e[99b~": . ~/.bashrc'
bind '"\C-xr": "\e[99i~\e[99b~"'
bash
클릭하면 C-x r
이해할 수 없는 오류 메시지가 기록되는 것을 제외하고는 작동합니다 .
\udccf\udccf\udccf\udccf\udccf\udccf: command not found
나는 이것이 내가 변경한 다른 설정과의 상호 작용으로 인한 것일 수 있다고 생각하여 ~/.bashrc
키 바인딩을 정의하는 3줄을 제외한 모든 항목을 제거했습니다 C-x r
.
하지만 여전히 오류 메시지가 있습니다.
: command not found
그래서 저는 bashrc
단 하나의 키 바인딩으로 더 간단한 접근 방식을 시도했습니다.
bind -x '"\C-xr": . ~/.bashrc'
이번에는 클릭하면 C-x r
오류가 발생합니다.
\udccf
: command not found
bind -x '"\C-xr": . ~/.bashrc'
그러나 파일의 줄에 주석을 달고 bashrc
대화형 셸에서 명령을 실행하면 bash
모든 것이 잘 작동합니다. 오류 메시지가 없으며 구성이 올바르게 재구성되었습니다.
그래서 나는 bash
(이미 완료된 경우) 재정의를 방지하기 위해 이 키 바인딩 주위에 가드를 작성해야 한다고 생각했습니다. 하지만 키 바인딩이 존재하는지 테스트하는 방법을 모르겠습니다. 또한 이러한 오류로 인해 어떤 일이 발생하는지 더 잘 이해하고 싶습니다.
이것이 중요한지는 모르겠지만 bash
직접 시작하지는 않습니다. 항상 if 로 시작합니다 zsh
. Bash 스크립트에 작성될 일부 명령을 테스트하려면 터미널(기본 셸로 사용됨)을 열고 zsh
거기서 실행합니다. bash
그렇다면 첫 번째 오류 메시지를 발생시킨 일부 환경 변수가 상속되었을 수 있습니까 bash
?zsh
또한 댓글 섹션에서 요청한 대로 다음은 hexdump -C ~/.bashrc
3개의 키 바인딩만 사용한 출력입니다.
00000000 62 69 6e 64 20 20 20 20 27 22 5c 65 5b 39 39 69 |bind '"\e[99i|
00000010 7e 22 3a 20 72 65 2d 72 65 61 64 2d 69 6e 69 74 |~": re-read-init|
00000020 2d 66 69 6c 65 27 0a 62 69 6e 64 20 2d 78 20 27 |-file'.bind -x '|
00000030 22 5c 65 5b 39 39 62 7e 22 3a 20 2e 20 7e 2f 2e |"\e[99b~": . ~/.|
00000040 62 61 73 68 72 63 27 0a 62 69 6e 64 20 20 20 20 |bashrc'.bind |
00000050 27 22 5c 43 2d 78 72 22 3a 20 20 20 22 5c 65 5b |'"\C-xr": "\e[|
00000060 39 39 69 7e 5c 65 5b 39 39 62 7e 22 27 0a |99i~\e[99b~"'.|
0000006e
bashrc
다음은 다음만 포함하는 16진수 덤프입니다 bind -x '"\C-xr": . ~/.bashrc'
.
00000000 62 69 6e 64 20 2d 78 20 27 22 5c 43 2d 78 72 22 |bind -x '"\C-xr"|
00000010 3a 20 2e 20 7e 2f 2e 62 61 73 68 72 63 27 0a |: . ~/.bashrc'.|
0000001f
내 전체 콘텐츠는 다음과 같습니다 bashrc
.
case "$-" in
*i*) ;;
*) return ;;
esac
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
alias cdr='cd "$(ls -dt */ | head -1)"'
export HISTCONTROL="ignoreboth:erasedups"
export HISTIGNORE="clear:history:"
export HISTFILE="${HOME}/.bash_eternal_history"
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
export PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND}"
cd() {
if [ $# -eq 2 ]; then
builtin cd "${PWD/$1/$2}"
elif [ $# -eq 1 ]; then
builtin cd "$1"
else
builtin cd
fi
}
shopt -s autocd
shopt -s checkwinsize
shopt -s globstar
shopt -s histappend
shopt -s histreedit
shopt -s histverify
. /usr/share/bash-completion/bash_completion
. ~/.fzf.bash
. ~/.shrc
bind '" ": magic-space'
bind '"\C-xc": "\C-a\C-kvimdiff <() <()\C-b\C-b\C-b\C-b\C-b"'
bind '"\C-xf": character-search'
bind '"\C-xF": character-search-backward'
bind '"\e[99i~": re-read-init-file'
bind -x '"\e[99b~": . ~/.bashrc'
bind '"\C-xr": "\e[99i~\e[99b~"'
bind '"\C-x\C-s": "sudo !!\C-m\C-m"'
bind -x '"\C-x\C-t": fzf-file-widget'
bind '"\C-t": transpose-chars'
bind '"\C-x\C-v": "\C-e | vim -R -\C-m"'
bind '"\em": "\C-aman \ef\C-k\C-m"'
bind '"\e\C-b": "\C-e >/dev/null 2>&1 &\C-m"'
편집하다:
. ~/.bashrc
함수 내부에 명령을 래핑 하고 키 바인딩에서 후자를 호출해 보았습니다. 다음 구문을 사용하십시오.
bind '"\e[99i~": re-read-init-file'
bind -x '"\e[99b~": MyFunc'
bind '"\C-xr": "\e[99i~\e[99b~"'
MyFunc () {
. ~/.bashrc
}
오류가 함수 이름의 길이에 영향을 받는 것으로 나타났습니다. 다음은 왼쪽 열에 다양한 함수 이름이 포함되어 있고 오른쪽 열에 오류 메시지(있는 경우)가 포함되어 있는 표입니다.
┌───────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────┐
│ a │ \udc99: command not found │
│ ab │ \udc92: command not found │
│ abc │ : command not found │
│ abcd │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found │
│ abcde │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found │
│ abcdef │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found │
│ abcdefg │ no error │
│ abcdefgh │ : command not found │
│ abcdefghi │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found │
│ abcdefghij │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found │
│ abcdefghijk │ \udcdf\udcdf\udcdf\udcdf\udcdf: command not found │
│ abcdefghijkl │ \udcdf\udcdf\udcdf\udcdf: command not found │
│ abcdefghijklm │ \udcdf\udcdf\udcdf: command not found │
│ abcdefghijklmn │ \udcdf\udcdf: command not found │
│ abcdefghijklmno │ \udcdf: command not found │
│ abcdefghijklmnop │ : command not found │
│ abcdefghijklmnopq │ no error │
└───────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────┘
또한 명령 입력을 . ~/.bashrc
터미널에 다시 연결하는 다른 기능을 시도했습니다(에서 영감을 얻었습니다).여기):
bind '"\e[99i~": re-read-init-file'
bind -x '"\e[99b~": MyFunc'
bind '"\C-xr": "\e[99i~\e[99b~"'
MyFunc () {
. ~/.bashrc </dev/tty
}
결과는 다음과 같습니다.
┌──────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ a │ 9}: command not found │
│ ab │ \udcdd: command not found │
│ abc │ : command not found │
│ abcd │ no error │
│ abcde │ no error │
│ abcdef │ no error │
│ abcdefg │ no error │
│ abcdefgh │ : command not found │
│ abcdefghi │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found │
│ abcdefghij │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found │
│ abcdefghijk │ \udcdf\udcdf\udcdf\udcdf\udcdf: command not found │
│ abcdefghijkl │ \udcdf\udcdf\udcdf\udcdf: command not found │
│ abcdefghijklm │ \udcdf\udcdf\udcdf: command not found │
│ abcdefghijklmn │ \udcdf\udcdf: command not found │
│ abcdefghijklmno │ \udcdf: command not found │
│ abcdefghijklmnop │ : command not found │
│ abcdefghijklmnopq │ no error │
│ abcdefghijklmnopqr │ no error │
│ abcdefghijklmnopqrs │ no error │
│ abcdefghijklmnopqrst │ \udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf$: command not found │
└──────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘