这个安装脚本给我Unable to locate package
大多数程序的错误。
#! /bin/bash
apps=(
'python-dev',
'python-pip',
'python-numpy',
'python-scipy',
'python-matplotlib',
'ipython',
'ipython-notebook',
'python-pandas',
'python-sympy',
'python-nose',
'python-picamera',
'openssh-client',
'openssh-server',
'vim'
)
sudo apt-get update
# Loop over apps and install each one with default 'yes' flag
for app in "${apps[@]}"
do
sudo apt-get install $app -y
done
# configure ssh
sudo cp /etc/ssh/sshd_confi /etc/ssh/sshd_config.original
sudo chmod a-w /etc/ssh/sshd_config.original
piplist=(
'networkx',
'scikit-image'
)
for app in "${piplist[@]}"
do
sudo pip install -U $app
done
它只安装了vim。所以我想我的仓库列表没有更新,但我认为这就是“sudo apt-get update”的用途。
当我运行时sudo apt-get install python-dev
,它确实在脚本之外安装了包。
答案1
看起来你的 $app 为除 vim 之外的其他包名称附加了逗号。尝试从应用程序中删除逗号
或尝试
sudo apt-get install $(echo $app | sed 's/,//g') -y
代替
sudo apt-get install $app -y
和
sudo pip install -U $(echo $app | sed 's/,//g')
代替
sudo pip install -U $app
答案2
我应该替换的米琳的答案sudo apt-get install $app -y
就是sudo apt-get install $(echo $app | sed 's/,//g') -y
解决方案。
答案3
您可以删除数组每个成员后面的所有尾随逗号 ( ,
),这样您就不需要对apt-get install
命令进行任何其他修改。因此,您的脚本可能如下所示:
#!/bin/bash
apps=(
'python-dev'
'python-pip'
'python-numpy'
'python-scipy'
'python-matplotlib'
'ipython'
'ipython-notebook'
'python-pandas'
'python-sympy'
'python-nose'
'python-picamera'
'openssh-client'
'openssh-server'
'vim'
)
sudo apt-get update
# Loop over apps and install each one with default 'yes' flag
for app in "${apps[@]}"
do
sudo apt-get install $app -y
done