Bash-Script 不执行命令,但如果手动输入命令,则它可以工作

Bash-Script 不执行命令,但如果手动输入命令,则它可以工作

这是我的 bash 脚本:

#!/bin/bash
sleep 3
sudo apt-get update && echo 'y' | sudo apt-get upgrade
cd /opt/
sleep 5
wget http://dl.4players.de/ts/releases/3.0.13.6/teamspeak3-server_linux_amd64-3.0.13.6.tar.bz2
sleep 10
tar -jxvf teamspeak3-server_linux_amd64-3.0.13.6.tar.bz2
sleep 10
mv /opt/teamspeak3-server_linux_amd64 /opt/teamspeak
cd /opt/teamspeak
sudo echo 'cd /opt/teamspeak && chown -R root:root *'
sudo echo 'cd /opt/teamspeak && ./ts3server_startscript.sh start'
sudo echo 'cd /opt/teamspeak && ./ts3server_startscript.sh stop'
sudo echo 'cd /opt/teamspeak && ./ts3server_startscript.sh start serveradmin_password=XXX'

突然看起来最后 4 个命令不起作用。你知道为什么吗?它不是内容,因为它在我手动输入时起作用。

答案1

我认为你想要的不是echo命令,而是执行它们。尝试这个:

cd /opt/teamspeak && sudo chown -R root:root *
cd /opt/teamspeak && sudo ./ts3server_startscript.sh start
cd /opt/teamspeak && sudo ./ts3server_startscript.sh stop
cd /opt/teamspeak && sudo ./ts3server_startscript.sh start serveradmin_password=XXX

相关内容