语法错误:操作数预期(错误标记为">"

时间:2015-11-15 16:03:23

标签: bash unix

./ex6.bash: 줄 10: ((: > : syntax error: operand expected (error token is "> ")

这是我的代码:

#!/bin/bash

printf "Input first number => "
read num1
printf "Input second number => "
read num2

num1=$a1
num2=$a2
if (( $a1>$a2 ))
then
    while [ $a1==$a2 ];
    do
        let "a1 = $a1 - 1"
        let "a2 = $a2 + 1"
        if (( $a1==$a2 ))
        then
            printf " $num2 ~ $num1 mid point : $a1 \n"
            break
        elif (( $((a1 -1))==$a2 ))
        then
            printf " $num2 ~ $num1 mid point : $a1 \n"
            break
        fi
    done
else
    while [ $a1==$a2 ];
    do
        let "a1 = $a1 + 1"
        let "a2 = $a2 - 1"
        if (( $a1==$a2 ))
        then
            printf " $num1 ~ $num2 mid point : $a1 \n"
            break
        elif (( $((a1 -1))==$a2 ))
        then
            printf " $num1 ~ $num2 mid point : $a1 \n"
            break
        fi
    done
fi

出了什么问题,我该如何解决?我不知道该怎么做。

1 个答案:

答案 0 :(得分:1)

您永远不会为a1设置值,因此算术语句(($a1>$a2))会扩展为((>))。也许您的意思是a1=$num1而不是num1=$a1,但您根本不需要a1;你可以使用$num1。同样适用于a2num2