시스템에 존재하지 않는 command를 입력하면 bash는 function을 실행합니다 command_not_found_handle(). 이 함수에는 /usr/lib/command-not-found메시지를 인쇄 하는 스크립트 호출이 있습니다 .
우분투 12.04
이 스크립트의 변경 소스에 나의 첫번째 추측은 메시지를 인쇄하는 stdout대신 stderr,하지만 스크립트 I의 내가 읽고 있던 소스를 사용하면 패키지 누락 설치하려면 그냥 물어 구성 할 수 있음을 발견했다.
변수를 내 보내면 COMMAND_NOT_FOUND_INSTALL_PROMPT누락 된 패키지를 설치하라는 메시지가 표시됩니다.
pbm@ubuntu:~$ git
The program 'git' is currently not installed. You can install it by typing:
sudo apt-get install git
pbm@ubuntu:~$ export COMMAND_NOT_FOUND_INSTALL_PROMPT=""
pbm@ubuntu:~$ git
The program 'git' is currently not installed. You can install it by typing:
sudo apt-get install git
Do you want to install it? (N/y)y
sudo apt-get install git
[sudo] password for pbm:
이전 버전의 우분투
불행히도 COMMAND_NOT_FOUND_INSTALL_PROMPT다른 옵션이 거의 없습니다 .
1) 12.04에서 패키지를 설치하십시오-문제가되지 않아야합니다-파이썬에는 스크립트가 거의 없으므로 작동하지 않아야합니다!
2) 변경 stderr에 stdout. 그것을 편집 파일을 수행 /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.py하고 변화 stderr에 stdout라인 237 및 240에.
그 후 다음과 같이 사용할 수 있습니다.
pbm@ubuntu:~$ git
The program 'git' is currently not installed. You can install it by typing:
sudo apt-get install git
pbm@ubuntu:~$ `git`
//Installation begins
237 행과 240 행 -y에서 apt-get명령에 옵션을 추가 하면 구문을 사용할 수도 있습니다 !! | sh.
3) 다음과 같이 242 행에서이 스크립트를 수정할 수도 있습니다.
print >> sys.stderr, _("You can install it by typing:")
f = open("%s/.install-missing" % os.path.expanduser('~'),'w')
print >> sys.stderr, "sudo apt-get install %s" % packages[0][0]
print >> f, "sudo apt-get install %s" % packages[0][0]
f.close()
이런 식으로 file 명령을 얻을 수 ~/.install-missing있으므로 alias를 만들 수 있습니다.
alias im="chmod +x ~/.install-missing; ~/.install-missing"
전화하면 im패키지가 설치됩니다.
/usr/lib/command-not-found대한 언급이COMMAND_NOT_FOUND_INSTALL_PROMPT없습니까?