raspberry pi,脚本中的 apt-get 更新不起作用
raspberry pi, apt-get update in script does not work
当我运行:
sudo apt-get update
sudo apt-get upgrade
从命令行,它有效。
如果我把同一行放在脚本文件中 maintain.script:
echo UPDATING SYSTEM SOFTWARE – UPDATE
sudo apt-get update
echo UPDATING SYSTEM SOFTWARE – UPGRADE
sudo apt-get upgrade
和运行:
sudo ./maintain.sh
我收到错误:
E: Invalid operation update
E: Invalid operation upgrade
我已将脚本标记为可执行文件。
根据 FSQ 的评论更新
这是脚本文件:
#!/bin/bash
echo "UPDATING SYSTEM SOFTWARE – UPDATE"
apt-get update
echo "UPDATING SYSTEM SOFTWARE – UPGRADE"
apt-get upgrade
echo "UPDATING SYSTEM SOFTWARE – DISTRIBUTION"
apt-get dist-upgrade
echo "REMOVING APPLICATION ORPHANS"
apt-get autoremove –purge
echo "UPDATING FIRMWARE"
rpi-update
命令如下:
pi@raspberrypi2 ~/projects $ sudo ./maintain.sh
结果如下:
: not foundsh: 1: ./maintain.sh: #!/bin/bash
UPDATING SYSTEM SOFTWARE – UPDATE
E: Invalid operation update
UPDATING SYSTEM SOFTWARE – UPGRADE
E: Invalid operation upgrade
UPDATING SYSTEM SOFTWARE – DISTRIBUTION
E: Invalid operation dist-upgrade
REMOVING APPLICATION ORPHANS
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package –purge
UPDATING FIRMWARE
: not foundsh: 11: ./maintain.sh: rpi-update
将此添加到脚本的开头? #!/bin/bash
这就是它在 ubuntu 上的工作方式 不确定 raspbian
这是一个文件格式问题。我正在使用 Windows 记事本通过文件夹共享编辑文件,它使用不同的 \r\n 到 Linux。
这是更正我的脚本文件的命令:
sed -i 's/\r//' maintain.sh
这是我用来执行文件夹中所有脚本文件的脚本文件,并确保它们是可执行的:
#!/bin/bash
echo "Correcting script file formats"
for file in *.sh
do
echo $file
sed -i 's/\r//' $file
chmod +x $file
done
当我运行:
sudo apt-get update
sudo apt-get upgrade
从命令行,它有效。
如果我把同一行放在脚本文件中 maintain.script:
echo UPDATING SYSTEM SOFTWARE – UPDATE
sudo apt-get update
echo UPDATING SYSTEM SOFTWARE – UPGRADE
sudo apt-get upgrade
和运行:
sudo ./maintain.sh
我收到错误:
E: Invalid operation update
E: Invalid operation upgrade
我已将脚本标记为可执行文件。
根据 FSQ 的评论更新
这是脚本文件:
#!/bin/bash
echo "UPDATING SYSTEM SOFTWARE – UPDATE"
apt-get update
echo "UPDATING SYSTEM SOFTWARE – UPGRADE"
apt-get upgrade
echo "UPDATING SYSTEM SOFTWARE – DISTRIBUTION"
apt-get dist-upgrade
echo "REMOVING APPLICATION ORPHANS"
apt-get autoremove –purge
echo "UPDATING FIRMWARE"
rpi-update
命令如下:
pi@raspberrypi2 ~/projects $ sudo ./maintain.sh
结果如下:
: not foundsh: 1: ./maintain.sh: #!/bin/bash
UPDATING SYSTEM SOFTWARE – UPDATE
E: Invalid operation update
UPDATING SYSTEM SOFTWARE – UPGRADE
E: Invalid operation upgrade
UPDATING SYSTEM SOFTWARE – DISTRIBUTION
E: Invalid operation dist-upgrade
REMOVING APPLICATION ORPHANS
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package –purge
UPDATING FIRMWARE
: not foundsh: 11: ./maintain.sh: rpi-update
将此添加到脚本的开头? #!/bin/bash
这就是它在 ubuntu 上的工作方式 不确定 raspbian
这是一个文件格式问题。我正在使用 Windows 记事本通过文件夹共享编辑文件,它使用不同的 \r\n 到 Linux。
这是更正我的脚本文件的命令:
sed -i 's/\r//' maintain.sh
这是我用来执行文件夹中所有脚本文件的脚本文件,并确保它们是可执行的:
#!/bin/bash
echo "Correcting script file formats"
for file in *.sh
do
echo $file
sed -i 's/\r//' $file
chmod +x $file
done