|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
[Solved] Why code run not correctly
Hi there can anyone help me here is my code Code:
echo "Type in a positive number" read X I=2 while [ $(( $X > $I )) ] do if [ $(( $X % $I == 0)) ] then echo "It is not prime" break else if [ $(($X - $I == 1)) ] then echo "It is prime" break else I=$(( $I + 1)) fi fi done idk why when I am entering there 5 it says that it is not prime any ideas why it is working not cirrectly??? Thanks in advanace!! |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Hi The closing brackets were placed at the wrong places: Code:
echo "Type in a positive number"
read X
I=2
while [ $X>$I ]
do
if [ $(($X%$I)) == 0 ]
then
echo "It is not prime"
break
else
if [ $(($X-$I)) == 1 ]
then
echo "It is prime"
break
else
I=$(( $I + 1))
fi
fi
done |
| The Following User Says Thank You to guruprasadpr For This Useful Post: | ||
FUTURE_EINSTEIN (07-12-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
|
|
#4
|
||||
|
||||
|
Hi
Its not just about spaces, its about the brackets as mentioned earlier. Try running the corrected code which i pasted, it works fine. Guru |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Quote:
oh, get my mistake |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Solved] problem - connecting code with external file | Telis | Shell Programming and Scripting | 4 | 03-15-2012 02:14 PM |
| [Solved] Running shell code in AppleScript without Terminal | ShadowofLight | OS X (Apple) | 9 | 06-30-2011 03:52 PM |
| [solved] merging two files and writing to another file- solved | mlpathir | Shell Programming and Scripting | 1 | 10-07-2010 06:41 PM |
| HP-UX will not boot correctly | intern | UNIX for Dummies Questions & Answers | 5 | 05-24-2006 08:19 AM |
| why the PATH can not be set correctly? | yishen | UNIX for Dummies Questions & Answers | 5 | 07-23-2002 10:09 PM |
|
|