错误D:我已经尝试了从坏elif到解析错误的很多事情.使固定

  • 本文关键字:错误 elif bash shell
  • 更新时间 :
  • 英文 :


可能的重复:
如果语句不遵循其条件

我相信我的卑诗省或变量是错误的,但我可能错了。

这是我的代码。

#!/bin/bash
#this is a game that is two player and it is a race to get to 
#100 before the other player
echo "Player 1 name?"
read p1
echo "Player 2 name?"
read p2
echo "Okay $p1 and $p2. $p1 will go first"
p1s=0
p2s=0
pt=1
while [ $pt -eq 1 ]; do
    echo "roll or stay"
    read choice
if [ $choice ="r" ]; then
    die=$(($RANDOM%6+1))
if [ $choice ="s" ]; then
    echo "Okay $p1 your score is $p1s"
    echo "$p2 turn now"
    sleep 1
    count=0
    pt=2
else
    pt=1
    fi
fi
if [ $die -eq 1 ]; then
    p1s=$(echo "$p1s-$count" |bc)
    echo "You rolled a 1. Your score is $p1s"
    echo "$p2 turn now."
    sleep 1
    count=0
    pt=2
elif [ $die -gt 1 ]; then
    p1s=$(echo "$p1s+$die" |bc)
    count=$(echo "$count+$die" |bc)
    echo "You rolled a $die. Your score is $p1s"
    pt=1
fi

if [ $p1s -gt 99 ]; then
    echo "$p1 won. $p2 lost"
    echo "would you like to play again?"
    read again
else
if [ $again ="yes" ]; then
    echo "Okay one second."
    sleep 1
    clear
    bash num.sh
else
if [ $again = "no" ]; then
    exit
else
    echo "I guess no then?"
    exit
        fi
    fi
fi
done

发生的是这个

播放器1名?

1

播放器2名称?

2

好的1和2。1将首先

滚动或留下

r

num.SH:第24行:[:r:UNARY操作员预期

num.sh:第42行:[:-eq:Unary Operator Expect

num.SH:第51行:[:-GT:Unary Operator Expect

好一秒钟。

播放器1名?

在这里发现了很多错误等。然后开始。

预先感谢您。

我想有条件检查选择变量有错误的语法,应将其写入:

if [ "$choice" -eq "r" ]; then
...

或增强的括号

if [[ "$choice" == "r" ]]; then
...

相关内容

  • 没有找到相关文章

最新更新