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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-25-2004, 10:41 PM
|
#1
|
Member
Registered: Mar 2004
Posts: 58
Rep:
|
-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!"
|
|
|
03-25-2004, 10:42 PM
|
#2
|
Member
Registered: Mar 2004
Posts: 58
Original Poster
Rep:
|
Imigine that the #!/bin/sh is there like it is in my script
|
|
|
03-25-2004, 11:05 PM
|
#3
|
Member
Registered: Feb 2004
Location: Australia
Distribution: Ubuntu, Fedora 10
Posts: 632
Rep:
|
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.
|
|
|
03-25-2004, 11:16 PM
|
#4
|
Member
Registered: Mar 2004
Posts: 58
Original Poster
Rep:
|
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??
|
|
|
03-25-2004, 11:20 PM
|
#5
|
Member
Registered: Feb 2004
Location: Australia
Distribution: Ubuntu, Fedora 10
Posts: 632
Rep:
|
what line
|
|
|
03-25-2004, 11:38 PM
|
#6
|
Member
Registered: Mar 2004
Posts: 58
Original Poster
Rep:
|
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 ???
|
|
|
03-25-2004, 11:39 PM
|
#7
|
Member
Registered: Mar 2004
Posts: 58
Original Poster
Rep:
|
the only + sign I see in the script is the guesses=$(( $guesses + 1 ))
|
|
|
03-26-2004, 09:45 PM
|
#8
|
Member
Registered: Feb 2004
Location: Australia
Distribution: Ubuntu, Fedora 10
Posts: 632
Rep:
|
not sure because it works for me, what dirtro are u using
|
|
|
03-27-2004, 12:39 AM
|
#9
|
Member
Registered: Mar 2004
Posts: 58
Original Poster
Rep:
|
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:30 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|