오래된 질문은 알 수 있지만 지금은 비슷한 상황입니다. 일반적으로 나는 sudo aptitude install -P PACKAGE_NAME설치하기 전에 항상 묻는 것을 사용합니다. 그러나 현재 데비안의 기본 패키지 관리자는 apt|apt-get이 기능이 없습니다. 물론 나는 여전히 aptitude그것을 설치 하고 사용할 수 있습니다 ... 그러나 나는 apt-get설치하기 전에 물어볼 작은 sh / bash 래퍼 함수 / 스크립트를 작성했습니다 . 그것은 실제로 원시적이며 터미널에서 함수로 작성했습니다.
$ f () { sudo apt-get --simulate install "$@" | grep -v '^Inst\|^Conf'; read -p 'Do You want to continue (y/N): ' ans; case $ans in [yY] | [yY][eE][sS]) sudo apt-get -y install "$@";; *);; esac; }
이제 더 명확하게하자 :
f () {
# Do filtered simulation - without lines contains 'Inst' and 'Conf'
sudo apt-get --simulate install "$@" | grep -v '^Inst\|^Conf';
# Interact with user - If You want to proceed and install package(s),
# simply put 'y' or any other combination of 'yes' answer and tap ENTER.
# Otherwise the answer will be always not to proceed.
read -p 'Do You want to continue (y/N): ' ans;
case $ans in
[yY] | [yY][eE][sS])
# Because we said 'yes' I put -y to proceed with installation
# without additional question 'yes/no' from apt-get
sudo apt-get -y install "$@";
;;
*)
# For any other answer, we just do nothing. That means we do not install
# listed packages.
;;
esac
}
이 기능을 sh / bash 스크립트로 사용하려면 my_apt-get.sh컨텐츠 를 사용하여 스크립트 파일을 작성 하십시오 (참고 : 리스팅에는 주석이 포함되어 있지 않으므로 ;-)).
#!/bin/sh
f () {
sudo apt-get --simulate install "$@" | grep -v '^Inst\|^Conf';
read -p 'Do You want to continue (y/N): ' ans;
case $ans in
[yY] | [yY][eE][sS])
sudo apt-get -y install "$@";
;;
*)
;;
esac
}
f "$@"
그런 다음 예를 들어로 넣고 ~/bin/실행 가능하게하십시오 $ chmod u+x ~/bin/my_apt-get.sh. 디렉토리 ~/bin가 PATH변수에 포함되어 있으면 다음과 같이 간단히 디렉토리 를 실행할 수 있습니다.
$ my_apt-get.sh PACKAGE_NAME(S)_TO INSTALL
참고 :
- 코드는를 사용
sudo합니다. root계정 을 사용하는 경우 계정을 조정해야합니다.
- 이 코드는 쉘 자동 완성을 지원하지 않습니다
- 코드가 쉘 패턴과 어떻게 작동하는지 전혀 모릅니다 (예 : "!", "*", "?", ...)