本帖最后由 jjjzw 于 2022-3-27 16:52 编辑
这两天在Ubuntu下搭建饥荒(DST)服务器时遇到了一个问题:
服务器启动文件所在路径为:
~/.steam/steamapp/common/Don\'t\ Starve\ Together/bin
在~/路径下建立run.sh
[Shell] 纯文本查看 复制代码 #!/bin/bash
install_dir="/root/.steam/steamapp/common/Don\'t\ Starve\ Together"
cluster_name="Cluster_1"
dontstarve_dir="/root/.klei/DoNotStarveTogether"
function fail()
{
echo Error: "$@" >&2
exit 1
}
function check_for_file()
{
if [ ! -e "$1" ]; then
fail "Missing file: $1"
fi
}
check_for_file "$dontstarve_dir/$cluster_name/cluster.ini"
check_for_file "$dontstarve_dir/$cluster_name/cluster_token.txt"
check_for_file "$dontstarve_dir/$cluster_name/Master/server.ini"
check_for_file "$dontstarve_dir/$cluster_name/Caves/server.ini"
check_for_file "$install_dir/bin"
cd "$install_dir/bin" || fail
run_shared=(./dontstarve_dedicated_server_nullrenderer)
run_shared+=(-console)
run_shared+=(-cluster "$cluster_name")
run_shared+=(-monitor_parent_process $$)
run_shared+=(-shard)
"${run_shared[@]}" Caves | sed 's/^/Caves: /' &
"${run_shared[@]}" Master | sed 's/^/Master: /'
运行
[Shell] 纯文本查看 复制代码 sudo ./run.sh
后报错:无法找到目录/root/.steam/steamapp/common/Don\'t\ Starve\ Together/bin
这时在Terminal中直接运行
[Shell] 纯文本查看 复制代码 cd /root/.steam/steamapp/common/Don\'t\ Starve\ Together/bin
却可以成功进入目录
在网上搜索该问题,得到答案:
运行sh文件后产生一个子shell,执行shell脚本是在子shell上执行的,当shell脚本执行完退出子shell,所以看不到结果应当使用source *.sh
因此我改用
[Shell] 纯文本查看 复制代码 source run.sh
依然出现了同样的报错,并且强制断开了ssh连接
多次尝试后依然失败,最后实在没办法只能将脚本放在bin目录下source,该问题依然没能解决
求问各位大佬这是什么原因导致的,应该怎么解决! |