我无法从我在这个C-Shell Linux程序中的输入中减去一个代码

问题描述 投票:0回答:1

这是我正在制作的第一个C-Shell Linux程序,我似乎无法获得包含输入的输出 - 1.对我做错的任何想法?

码:

#!/bin/csh

echo "Please enter a number: "
 read input
    if [[ $input -lt '100' ]]
    then
        echo "The number is less than 100"

        elif [[ $input -eq '100' ]]
        then
            echo "The number is equal to 100"

            else [[ $input -gt '100' ]]
                echo "The number is greater than 100"
read newi                
while [ "$newi" -gt 0 ]
    do echo "Please wait $newi more seconds"
    input=$(( newi - 1 ))
    done
echo "The script has ended. Goodbye!"
fi
csh
1个回答
0
投票

所以我明白了!当我试图在同一行上计算数学问题时,我有一个else语句。我还在我的代码末尾而不是if语句本身结束了我的if语句。这导致我的代码在我想要它之前结束。我还意识到,当我可以使用相同的变量来简化代码时,我输入了一个新变量。在我离开一段时间重新组合后,我将它拼凑在一起。谢谢你帮助我集思广益,大家好!

#!/bin/csh

#promt user for input and receive for variable
echo "Please enter a number: "
 read input

 #determine if number is less than, greater than, or equal to 100
    if [[ $input -lt '100' ]]
    then
        echo "The number is less than 100"

    elif [[ $input -eq '100' ]]
    then
        echo "The number is equal to 100"
    else
        echo "The number is greater than 100"
    fi
    #subract 1 from value if greater than 0
while [ $input -gt 0 ]
    do echo "Please wait $input more seconds"
    input=$(( input - 1 ))
    done
echo "The script has ended. Goodbye!"
© www.soinside.com 2019 - 2024. All rights reserved.