우분투에서 bash에게 저주 단어를 어떻게 가르칠 수 있나요?

우분투에서 bash에게 저주 단어를 어떻게 가르칠 수 있나요?

Bash가 알 수 없는 명령(단어?)을 발견하면 다음을 수행합니다.

The program 'hello' can be found in the following packages:
 * hello
 * hello-debhelper
Try: sudo apt-get install <selected package>

내가 알고 싶은 것은 이것이 어떻게 수행되는지, 그래서 그것을 편집하거나 그 전에 뭔가를 추가하여 집에서 만든 사전에서 알 수 없는 단어를 교차 검사할 수 있다는 것입니다. 이 사전에는 문구:응답 쌍이 있고 출력으로 보낼 수 있습니다.

나는 주변에서 그것을 충분히 찾지 못한 것에 대해 유죄입니다 .. 그러나 내가 파헤치려고 시도한 몇 가지 bash 가이드에는 이것에 대한 아무것도 없었습니다. 어쩌면 내가 잘못된 곳을 보고 있는 것일 수도 있습니다. 어떤 조언이 있습니까?

그리고 네, 저는 이 일을 하고 있어서 프로그램이 실패할 때 wtf를 입력할 때마다 멋진 일이 저에게 다시 던져지기를 원합니다...

답변1

/etc/bash.bashrc함수 정의를 찾으십시오 command_not_found_handle.

해당 동작을 제거하려면 이것을 .bashrc에 넣으십시오.

[[ $(type -t command_not_found_handle) = "function" ]] && 
  unset -f command_not_found_handle

사용자 정의하고 싶다면 할 수 있습니다

# see http://stackoverflow.com/questions/1203583/how-do-i-rename-a-bash-function
alias_function() {
  eval "${1}() $(declare -f ${2} | sed 1d)"
}

alias_function orig_command_not_found_handle command_not_found_handle 

command_not_found_handle() {
  command=$1
  shift
  args=( "$@" )

  do your stuff before
  orig_command_not_found_handle "$command" "${args[@]}"
  do your stuff after
}

답변2

이것잠재적으로 유용할 수도 있습니다...

command-not-found 패키지는 마법의 응답을 제공합니다. 맞춤설정이 가능한지는 잘 모르겠지만 한 번 볼만한 가치가 있을 것 같습니다.

내 생각에 당신이 하려는 일을 하는 또 다른 옵션은 'wtf' 또는 이와 유사한 것을 입력할 때마다 메시지를 인쇄하는 별칭을 .bashrc 파일에 추가하는 것입니다.

alias wtf='echo "chill out man"'

이것을 ~/.bashrc 파일에 추가하고 다음을 수행하십시오.source $HOME/.bashrc

그러면 wtf터미널에 입력할 때마다 메시지가 인쇄됩니다. 또한 이 별칭 호출을 더 자세한 메시지나 유사한 내용을 인쇄하는 스크립트로 만들 수도 있습니다. 가능성은 무궁무진합니다!

답변3

이 동작은 시스템 전체 Bash 구성 파일에 정의되어 있습니다 /etc/bash.bashrc.

# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found ]; then
  function command_not_found_handle {
    # check because c-n-f could've been removed in the meantime
    if [ -x /usr/lib/command-not-found ]; then
      /usr/bin/python /usr/lib/command-not-found -- "$1"
      return $?
    elif [ -x /usr/share/command-not-found ]; then
      /usr/bin/python /usr/share/command-not-found -- "$1"
      return $?
    else
      return 127
    fi
  }
fi

이를 맞춤설정하려면 다음 함수를 직접 재정의하세요 ~/.bashrc.

function command_not_found_handle {
  echo "Sorry, smotchkiss, try again."
}

답변4

@user606723, 이 동작을 완전히 제거하려면 다음을 수행하세요.

sudo apt-get remove command-not-found command-not-found-data 

그래도 문제가 해결되지 않으면 다음을 시도해 보세요.

sudo apt-get purge command-not-found command-not-found-data 

동작을 다시 되돌리려면 다음을 수행하세요.

sudo apt-get install command-not-found

관련 정보