gpt4 book ai didi

bash - 意外标记 `}' 附近的语法错误`

转载 作者:行者123 更新时间:2023-12-03 22:41:47 24 4
gpt4 key购买 nike

我正在编写一个 shell 脚本来为游戏 risk of rain 创建一个新的保存文件。我试图做到这一点,以便解锁的每个可用部分,例如成就、怪物日志、工件等都可以一次全部添加到文件中,或者用户可以选择哪些他们想要添加。我是编写 shell 脚本的新手,我不太确定为什么在运行我目前拥有的内容时出现错误 syntax error near unexpected token `}'我的脚本。如果有人能向我解释为什么我会收到错误、如何修复错误和/或如何改进我的脚本,将不胜感激。如果重要的话,我也在 Mac OS X 上。这是我的脚本。

#!/bin/bash
mkdir ~/Desktop/ror_save_unlock_all

echo "This script takes ~/Library/Application Support/com.riskofrain.riskofrain/Save.ini and backs it up to ~/Desktop/ror_save_unlock_all/originalSave. It generates a new Save.ini that is built to your specifications, unlocking all items and achievements or just the ones you choose, and replaces the existing Save.ini with the new one." >> ~/Desktop/ror_save_unlock_all/README.txt

mkdir ~/Desktop/ror_save_unlock_all/originalSave

cp ~/Library/Application\ Support/com.riskofrain.riskofrain/Save.ini ~/Desktop/ror_save_unlock_all/originalSave/

cd ~/Desktop/ror_save_unlock_all

echo -n 'How would you like the new Save.ini to be built? Press 1 for all unlocks or 2 to customize.'
read text
if [ $text = "1" ]
then
{
echo "[Achievement]" >> EOF1

count=1

while [ $count -lt 55 ]
do
echo "acheivement${count}=\"2\"" >> EOF2
count=`expr $count + 1`
done

echo "[Record]" >> EOF3

count=1

while [ $count -lt 31 ]
do
echo "mons${count}=\"1\"" >> EOF4
count=`expr $count + 1`
done

count=1

while [ $count -lt 110 ]
do
echo "item${count}=\"1\"" >> EOF5
count=`expr $count + 1`
done

count=1

while [ $count -lt 10 ]
do
echo "artifact${count}=\"1\"" >> EOF6
count=`expr $count + 1`
done

cat EOF1 EOF2 EOF3 EOF4 EOF5 EOF6 > Save.ini

rm EOF1 EOF2 EOF3 EOF4 EOF5 EOF6

cp -force ~/Desktop/ror_save_unlock_all/Save.ini ~/Library/Application\ Support/com.riskofrain.riskofrain/Save.ini

echo "Original Save.ini successfully overwritten."

exit

}

elif [ $text = "2" ]; then
{
echo "You selected customize. Now we will build a custom Save.ini"
echo -n "Press 1 if you want to unlock all achievements, press 2 to continue without unlocking all achievements."
read text
if [ $text = "1" ]; then

{
echo "[Achievement]" >> EOF1
count=1
while [ $count -lt 55 ]
do
echo "acheivement${count}=\"2\"" >> EOF2
count=`expr $count + 1`
done

echo "All achievements successfully unlocked."
echo -n "Press 1 to make the Save.ini and replace the existing one with it and then exit, or press 2 to customize it further."
read text
if [ $text = "1" ]; then
{
cat EOF1 EOF2 > Save.ini
rm EOF1 EOF2
cp -force ~/Desktop/ror_save_unlock_all/Save.ini ~/Library/Application\ Support/com.riskofrain.riskofrain/Save.ini
echo "Original Save.ini successfully overwritten."
exit
}

elif [ $text = "2" ] then;
{
echo -n "Press 1 to unlock all monster logs, or press 2 to continue without unlocking all monster logs."
read text
if [ $text = "1" ]; then
{
echo "[Record]" >> EOF3

count=1
while [ $count -lt 31 ]
do
echo "mons${count}=\"1\"" >> EOF4
count=`expr $count + 1`
done

echo "All achievements successfully unlocked."
echo -n "Press 1 to make the Save.ini and replace the existing one with it and then exit, or press 2 to customize it further."
read text
}
}
}
}

最佳答案

您的脚本有一些错误:- 第 93 行:elif [ $text = "2"] then; 应更改为 elif [ $text = "2"];然后- 如果 bash 中的命令必须有 fi 来关闭条件。可以引用http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html希望这有帮助

关于bash - 意外标记 `}' 附近的语法错误`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35690375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com