LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   -ne argument expected WHY doesnt this work (https://www.linuxquestions.org/questions/linux-newbie-8/ne-argument-expected-why-doesnt-this-work-162478/)

VisionZ 03-25-2004 11:41 PM

-ne argument expected WHY doesnt this work
 
I,m having a problem with this script, it is supposed to be a random number guessing game but it wont work. Can anyone tell me why????

here is the code

Code:

biggest=200
smallest=1
large=201
little=-1
guess=0
guesses=0
variable=$(( $$ % biggest ))


while [ $guess -ne $number ]
do
        echo -n "please guess a number"
        read guess
        if [ "$guess" -lt $variable ]
        then
                echo "The number is higher than that"
        elif [ "$guess" -gt $variable ]
        then
                echo "pick a smaller number"
        elif [ "$guess" -gt $large ]
        then
                echo "number is way to big, always pick lower than 200 or will be here all night!!"
        elif [ "$guess" -lt $little ]
        then
                echo "Its not a negative number, guess a positive number please"
        fi
        guesses=$(( $guesses + 1 ))
done

echo "Finally your got it. your guessed $variable finally in $guesses guesses!"


VisionZ 03-25-2004 11:42 PM

Imigine that the #!/bin/sh is there like it is in my script

jax8 03-26-2004 12:05 AM

I got it working this way, I just renamed the variable $number to $variable because $number did not exist in your code.


#!/bin/sh

biggest=200
smallest=1
large=201
little=-1
guess=0
guesses=0
variable=$(( $$ % biggest ))


while [ $guess -ne $variable ]
do
echo -n "please guess a number"
read guess
if [ "$guess" -lt $variable ]
then
echo "The number is higher than that"
elif [ "$guess" -gt $variable ]
then
echo "pick a smaller number"
elif [ "$guess" -gt $large ]
then
echo "number is way to big, always pick lower than 200 or will be here all night!!"
elif [ "$guess" -lt $little ]
then
echo "Its not a negative number, guess a positive number please"
fi
guesses=$(( $guesses + 1 ))
done

echo "Finally your got it. your guessed $variable finally in $guesses guesses!"






-jax

VisionZ 03-26-2004 12:16 AM

Duh, but that code doesnt work for me either for some reason?????

I get this error message

[: +] bad number

then it echos my final statement??

jax8 03-26-2004 12:20 AM

what line

VisionZ 03-26-2004 12:38 AM

it doesnt say

it just says

./(scriptname)
[: +: bad number
Finally you got it. you guessed +964 % biggest (some cross looking character I cant type) finally on 0 guesses!


thats all it says? Is it in my last echo ???

VisionZ 03-26-2004 12:39 AM

the only + sign I see in the script is the guesses=$(( $guesses + 1 ))

jax8 03-26-2004 10:45 PM

not sure because it works for me, what dirtro are u using

VisionZ 03-27-2004 01:39 AM

dirtro , ? I ,m a total newb, I,m using cywin for windows though if thats what your asking.


All times are GMT -5. The time now is 01:14 PM.