Tra*_*ack 2 package-management command-line apt
我有一个简单的 shell 脚本,用于更新 Firefox。它的内容是:
#!/bin/sh
sudo apt-get pruge firefox
sudo apt-get install firefox
Run Code Online (Sandbox Code Playgroud)
这就是全部。现在,当我在终端中运行文件时,按顺序使用,
cd Desktop/Batch\ Files
sudo chmod 775 Firefox.sh
sudo ./Firefox.sh
Run Code Online (Sandbox Code Playgroud)
输出表明pruge操作无法完成,但文件的其余部分运行。
这是确切的输出:
sudo: unable to resolve host ubuntu: Connection timed out
E: Invalid operation pruge
sudo: unable to resolve host ubuntu: Connection timed out
Reading package lists... Done
Building dependency tree
Reading state information... Done
firefox is already the newest version (57.0.1+build2-0ubuntu0.16.04.1).
0 upgraded, 0 newly installed, 0 to remove and 261 not upgraded.
Run Code Online (Sandbox Code Playgroud)
尽管很烦人,但我仍然可以逐行运行代码,并且purge操作有效。
您的脚本中有拼写错误,应该是purge而不是pruge. 到目前为止,如果您使用sudo script.sh. 所以你的脚本应该是:
#!/bin/sh
apt-get purge firefox
apt-get install firefox
Run Code Online (Sandbox Code Playgroud)
-y即使有多个软件包要安装,您也希望在安装上放置标志以使其自动安装。所以改变:
apt-get install firefox
Run Code Online (Sandbox Code Playgroud)
进入:
apt-get install -y firefox
Run Code Online (Sandbox Code Playgroud)
但是,如果您希望输出静音,则可以使用该-qq选项(这意味着-y),在这种情况下,您还需要提供清除-y或-qq选项,但两个命令都将静默运行。一个完全无声的脚本示例:
#!/bin/sh
apt-get purge -qq firefox &&
apt-get install -qq firefox
Run Code Online (Sandbox Code Playgroud)
您肯定想知道为什么我将它们&&放入脚本中:这会导致第二个命令仅在第一个命令成功时运行。
但是通常不需要清除 Firefox 来安装新版本。一个就sudo apt-get update && sudo apt-get install --reinstall firefox足够了,因为无论如何配置文件和设置都不会被清除。