LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-25-2004, 10:41 PM   #1
VisionZ
Member
 
Registered: Mar 2004
Posts: 58

Rep: Reputation: 15
-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!"
 
Old 03-25-2004, 10:42 PM   #2
VisionZ
Member
 
Registered: Mar 2004
Posts: 58

Original Poster
Rep: Reputation: 15
Imigine that the #!/bin/sh is there like it is in my script
 
Old 03-25-2004, 11:05 PM   #3
jax8
Member
 
Registered: Feb 2004
Location: Australia
Distribution: Ubuntu, Fedora 10
Posts: 632

Rep: Reputation: 31
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

Last edited by jax8; 03-25-2004 at 11:06 PM.
 
Old 03-25-2004, 11:16 PM   #4
VisionZ
Member
 
Registered: Mar 2004
Posts: 58

Original Poster
Rep: Reputation: 15
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??
 
Old 03-25-2004, 11:20 PM   #5
jax8
Member
 
Registered: Feb 2004
Location: Australia
Distribution: Ubuntu, Fedora 10
Posts: 632

Rep: Reputation: 31
what line
 
Old 03-25-2004, 11:38 PM   #6
VisionZ
Member
 
Registered: Mar 2004
Posts: 58

Original Poster
Rep: Reputation: 15
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 ???
 
Old 03-25-2004, 11:39 PM   #7
VisionZ
Member
 
Registered: Mar 2004
Posts: 58

Original Poster
Rep: Reputation: 15
the only + sign I see in the script is the guesses=$(( $guesses + 1 ))
 
Old 03-26-2004, 09:45 PM   #8
jax8
Member
 
Registered: Feb 2004
Location: Australia
Distribution: Ubuntu, Fedora 10
Posts: 632

Rep: Reputation: 31
not sure because it works for me, what dirtro are u using
 
Old 03-27-2004, 12:39 AM   #9
VisionZ
Member
 
Registered: Mar 2004
Posts: 58

Original Poster
Rep: Reputation: 15
dirtro , ? I ,m a total newb, I,m using cywin for windows though if thats what your asking.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
If your hardware does not work as expected! Keruskerfuerst SUSE / openSUSE 1 11-06-2005 05:43 AM
Why doesnt my USB mouse doesnt work? barkha Linux - Hardware 2 08-16-2005 11:31 AM
Alsa Doesnt work Creeps Linux - General 1 09-14-2004 12:50 AM
gethostbyname() doesnt always work nodger Programming 1 01-22-2004 10:56 AM
How does passing argument to main work Linh Programming 5 06-27-2003 01:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration