question on shell script

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions question on shell script
# 1  
Old 04-02-2011
Error 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?!
Code:
 
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

Last edited by moonlips; 04-02-2011 at 12:36 PM..
# 2  
Old 04-02-2011
Something's wrong in the syntax of the if/then/else statements.
# 3  
Old 04-02-2011
Quote:
Originally Posted by Franklin52
Something's wrong in the syntax of the if/then/else statements.

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

Its assignment given by teacher

Thanks
# 4  
Old 04-02-2011
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.
This User Gave Thanks to pludi For This Post:
# 5  
Old 04-04-2011
Code:
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 ----------

Quote:
Originally Posted by Franklin52
Something's wrong in the syntax of the if/then/else statements.
Hi,

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

Last edited by DukeNuke2; 04-03-2011 at 05:31 PM..
# 6  
Old 04-04-2011
Run the script in debug mode by placing
Code:
set -x

after the shebang line.
This User Gave Thanks to Franklin52 For This Post:
# 7  
Old 04-05-2011
Quote:
i tried to fix it. Its working now but it didnt give me the result which i want !!!!
What do you want? to print the fib. series? What are the conditions you are trying to avoid?

Last edited by pkabali; 04-05-2011 at 01:52 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script question

As per code it is getting matched. not sure why it assigning to cols=0. Any inputs please. Input : passed is shell.sh c tablename. if ; then cols=1 table=$2 else cols=0 table=$1 fi (1 Reply)
Discussion started by: ramkumar15
1 Replies

2. Shell Programming and Scripting

Shell script question

Hi all, can you plz check whether the below code is correct & some inputs. I need to read the below file and process it. input : /home/ibm/var.txt urgent not urgent not needed. #!/usr/bin/ksh VAR=/home/ibm/var.txt if ] then (7 Replies)
Discussion started by: ramkumar15
7 Replies

3. Homework & Coursework Questions

question in shell script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a Bourne shell script which: • Has one command line argument. • If the command line argument is a... (5 Replies)
Discussion started by: abood1190
5 Replies

4. Homework & Coursework Questions

Question on shell script

Hiiiiiiiiiiiii all, Please i want your help fast, the teacher gave us this assignment can u help me to write it? this is the question: Write a shell script to point all prime numbers from the fibonacci series of integer N? using Red hat Os Thanks all and waiting for ur answers... (1 Reply)
Discussion started by: moonlips
1 Replies

5. Shell Programming and Scripting

shell script question

I have script as following.. server_status= some command | grep "Total error: 0" if ; then echo " Server $(hostname) is Down" >>Result fi else echo " Server is OK on $(hostname)" >>Result the if command seems to be not working properly for some... (13 Replies)
Discussion started by: s_linux
13 Replies

6. Shell Programming and Scripting

shell script question

Hi, The contents of my file is below: Name,Location,Degree,Gender,Awards Robert,Philadelphia,Accounting,Male,5 Jane,Chicago,Business,Female,2 Allan,New York,Engineering,Male,6 Tom,Detroit,Computer Science,Male,10 Nancy,Milwaukee,Engineering,Female,4 I want to add a "ID" in the 1st line... (2 Replies)
Discussion started by: xinoo
2 Replies

7. Shell Programming and Scripting

Shell Script question

Hello Experts, I am new at this and need some help. I am looking for a delete command that allows me after I grep for the hostname to delete all the lines between two characters. for example I want to delete the first line all the way up to the } character host test019 { hardware ethernet... (10 Replies)
Discussion started by: ryanique
10 Replies

8. UNIX for Dummies Questions & Answers

Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies

9. Shell Programming and Scripting

Shell script question

Hello, i am doing a project for school and i cannot figure out whats wrong with my 2 programs they dont seem to work at all. the first program is called isprime and naturally it checks to see if hte number is prime or not here is my code: #!/usr/bin/bash num=$1 echo you typed if ... (2 Replies)
Discussion started by: jbou1087
2 Replies

10. Shell Programming and Scripting

shell script question

I am using ksh. There is a report having amounts in the following format, 34343.67- 2343.45 23434.89- I want to sum up all the amounts. For this I first need to find out if there is a minus sign at the end and prefix it before summing up. How to achieve this? I thought of using an... (2 Replies)
Discussion started by: tselvanin
2 Replies
Login or Register to Ask a Question