Linux Ubuntu:脚本在终端中工作,但不能.sh



问题摘要:我的脚本在终端中键入时正常工作,但是,从.sh文件在终端中执行时无法正常工作,这是为什么?

脚本:

echo World of Clucky - Frisnuk "33]0;Frisnuk - World of Cluckya"
#! /usr/bin/env bash
BINDIR="$(dirname "$(readlink -fn "$0")")"
cd "$BINDIR"
while true
do
source /home/clucky/MinecraftServers/Frisnuk/serverconfig/config.sh
#Start Server
    java -Xms2000M -Xmx2000M -jar $serverjar.jar nogui
    if [ "`date +%w%H`" = "001" ]
    then
#Delete map files for The End
    rm -R /Frisnuk_the_end
    echo "End has been successfully reloaded"
    echo "[`date +%D %T`] End Reloaded" >> /home/clucky/MinecraftServers/Frisnuk/EndRestart.txt
#Change Item of The Week
    weekofyear=`date +%y-%U`
    s=$(<serverconfig/ItemofTheWeek/item$weekofyear.txt)
    set -- $s
    itemoftheweekid=$2
    itemoftheweekprice=$3
    xmlstarlet edit -L -u "/scs-shop/itemStack[@type='double']" -v $itemoftheweekid /plugins/ShowCaseStandalone/ffs-storage/ffss_cac8480951254352116d5255e795006252d404d8
    xmlstarlet edit -L -u "/scs-shop/price[@type='double']" -v $itemoftheweekprice /plugins/ShowCaseStandalone/ffs-storage/ffss_cac8480951254352116d5255e795006252d404d8
fi
echo "If you want to stop the restart and shut the server off instead, please press Ctrl+C at this time"
for i in 5 4 3 2 1
do
    echo "$i..."
    sleep 1
done
echo "Restarting Server"
clear
done

它不是工作和运行服务器,而是这样说:

World of Clucky - Frisnuk 
/home/clucky/MinecraftServers/Frisnuk/craftminecraft.sh: 7: /home/clucky/MinecraftServers/Frisnuk/craftminecraft.sh: source: not found
Error: Unable to access jarfile .jar
If you want to stop the restart and shut the server off instead, please press Ctrl+C at this time
5...
4...
3...
2...
1...

我马上要去洗澡,但我今晚晚些时候或明天早上会回来。提前感谢您的帮助。

你在 shebang 之前放了一个echo,所以你的脚本是由 dash 而不是bash解释的

dash不包括source,因为它不是标准的。

纠正你的 shebang,它会解决问题。


source脚本的标准方法是使用 . 执行脚本。

而不是source ./myScript.sh,你做. ./myScript.sh。它们在bash中是一样的.

相关内容

  • 没有找到相关文章

最新更新