question on shell script

hiiiiiiiiiiiii,,I found an error on my following script but couldnt find it!!! Can you please help me as soon as possible?!

 
echo "enter a number "
read n
i=0
first=0
second=1
result=0
prime="true"
echo �n " $first $second "
while [ $i �lt $n ]
do
result=`expr $first + $second`
first=$second
second=$result
i=$result
for (( x=$i �lt ; x >=2; x--))
do
if [ `expr $i % $x` -eq 0 ]
then
prime="false"
break
else
prime="true"
if [ $prime="true" ]
then
echo $i
if=`expr $i + 1`
done

Course Name: Unix OS
Tutor Name: Mr. Aziz
college Name: Higher College of Technology

Something's wrong in the syntax of the if/then/else statements.

I tried to fix it but still couldnt find it :wall: .. Can u help me please??!!

Its assignment given by teacher

Thanks

Lets just say that every if needs a fi , and every do needs a done .

We will help you, but we won't do your work for you.

1 Like
echo "enter a number "
read n
z=0
a=0
fib=0
b=1
echo " fibancci series is "
while [ $z -le $n ]
do
fib=`expr $a + $b`
a=$b
b=$fib
x="true"
m=$fib
for((y=$m-1;y>=2;y--))
do
if [ `expr $m % $y` -eq 0 ]
then
x="false"
break
else
x="true"
fi
done
if [ $x ="true" ]
then
echo "$m"
fi
z=`expr $z + 1`
done

---------- Post updated at 11:38 PM ---------- Previous update was at 11:33 PM ----------

i tried to fix it. Its working now but it didnt give me the result which i want !!!!

---------- Post updated at 11:38 PM ---------- Previous update was at 11:38 PM ----------

i tried to fix it. Its working now but it didnt give me the result which i want !!!!

---------- Post updated 04-04-11 at 09:38 PM ---------- Previous update was 04-03-11 at 11:38 PM ----------

Hi,

did nu check my syntax?! i mean the new one?!!

Run the script in debug mode by placing

set -x

after the shebang line.

1 Like

What do you want? to print the fib. series? What are the conditions you are trying to avoid?

I want the prime numbers from the fib.series number which the user enter as input!!

---------- Post updated at 08:12 PM ---------- Previous update was at 07:26 PM ----------

I want to print the prime numbers of the fib. number which the user put as input. For example the user enter 5 then the output will be the prime number of fib. series of number 5..

The submisstion of this assignment is tomorow and i couldnt get the right output so far :frowning:

Try to figure out why this is wrong:

if [ $x ="true" ]

how is it wrong?!!
Oh god i am really going mad out of this script..

My mind jammed :wall:

Remember these statements in a shell need you to put spaces everywhere.

if [ $x = "true" ]
1 Like