LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Terminal problem (https://www.linuxquestions.org/questions/programming-9/terminal-problem-849341/)

tayyyar 12-09-2010 01:28 PM

Terminal problem
 
hi ı'm using fedora 14
and ı have a problem

ı want to try some codes to run in terminal but ı got error ı didn't figure out what is the problem and how can ı fix it please help me!! thank you :)

while[$i -le 10]
do
echo "$n * $i ='expr $i \* $n'"i='expr $i + 1'
done
----------
ı'm getiing line 1: [: missing ']'

xeleema 12-09-2010 01:37 PM

Greetings!

Assuming you're using the bash shell, try this;

while true
do
if [ $i -le 10 ]; then
echo "$n * $i = 'expr $i \* $n'"
i='expr $i + 1'
fi
done


If that doesn't work, I would re-read that chapter in your classbook.
:)

tayyyar 12-09-2010 01:48 PM

Quote:

Originally Posted by xeleema (Post 4186281)
Greetings!

Assuming you're using the bash shell, try this;

while true
do
if [ $i -le 10 ]; then
echo "$n * $i = 'expr $i \* $n'"
i='expr $i + 1'
fi
done


If that doesn't work, I would re-read that chapter in your classbook.
:)

thanks for your respond but that you wrote get inside the infinite loop wants

-le: unary operator expected

ı should check it my slayts one more time

GrapefruiTgirl 12-09-2010 01:55 PM

Quote:

-le: unary operator expected
Hint: Between the lines, that error is telling you that the variable you are comparing in your test, is not an integer. So, investigate how $i is getting set, i.e. is it getting set to a string value by accident or by logic error (or perhaps it is empty when the loop begins?)?

xeleema 12-09-2010 02:01 PM

@tayyyar
I left out a "then if i = 10...break" intentionally. We get quite a few "homework questions" here, and I wasn't sure if that's what your post was. :)


All times are GMT -5. The time now is 02:37 PM.