What is wrong with my script?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers What is wrong with my script?
# 1  
Old 05-28-2003
What is wrong with my script?

Hey guys, can someone help me with this script...
Code:
#!/bin/sh
dir=`pwd`
for i in *.f
do if [ -f ${i} ]
        then M=`wc -l < ${i}
                sed -e 's://.*::' < ${i} | \
                        (echo "//${i} -"$M ; cat - ) > $i.tmp
                chmod 700 $i ; mv ${i}.tmp $i
                echo $i --- $M
        fi
        if [ -d $i ]
        then cd ${i} ; $HOME/fred_sh ; cd $dir
        fi
done 2>> /dev/null

Thank you once again!

added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 02:57 PM..
# 2  
Old 05-28-2003
I was trying to look at this, but it's late and my eyes are crossing. Smilie

What are you trying to accomplish with this script? I see several mistakes, such as for i in *.f should be for i in `ls *.f` and the line $HOME/fred_sh doesn't actually do anything.. it just evaluates to a directory name which will probably return an error..

Plus the syntax such as ${i}, I believe, is only used in ksh, not sh.. but I could be wrong..

But if this is another class example like your last post, then I really encourage you and your classmates to try figuring it out using the book and each other rather than having someone do it for you on here..
# 3  
Old 05-28-2003
Question

We tried to compile it and when we run it it gave us an error in line 15 which is empty. We have no clue why is doing this. Thanks once again...
# 4  
Old 05-28-2003
I agree with oombera, if this is homework....get to work! With practice, unix is not that difficult. As for the error, you are missing a backquote in this line then M=`wc -l < ${i}


I didnt really carefully read your script, other than to look at the things oombera pointed out. Need to correct those.

What is the point of this block in your script anyway?
if [ -d $i ]
then cd ${i} ; $HOME/fred_sh ; cd $dir
fi
# 5  
Old 05-28-2003
It says there's an error on line 15 because where you have semicolons you are actually placing several lines of code on one line. Your code would be clearer like this:
Code:
01 #!/bin/sh
02 dir=`pwd`
03 for i in *.f
04 do
05   if [ -f ${i} ]
06     then M=`wc -l < ${i}
07     sed -e 's://.*::' < ${i} | \
08     (echo "//${i} -"$M ; cat - ) > $i.tmp
09     chmod 700 $i
10     mv ${i}.tmp $i
11     echo $i --- $M
12   fi
13   if [ -d $i ]
14     then cd ${i}
15     $HOME/fred_sh
16     cd $dir
17   fi
18 done 2>> /dev/null

I haven't changed anything, just reformatted the script..
# 6  
Old 05-28-2003
It's a sintax Error

As my friend google told U there is an error on the line:
then M=`wc -l < ${i}
You are missing a backquote.

Your whole script is 15 lines at all, so the shell tries to compile the script to the end trying to find the closing backquote.
# 7  
Old 05-29-2003
Question

Thanks guys. We don't know the purpose of the script. The question on the back of the chapter is: What does this script do? Thanks everybody...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

2. Shell Programming and Scripting

What is wrong with my script?

Dear All The following is part of my script: echo ${myarray} mytitle=`awk '{print substr(${myarray}, 0, length(${myarray})-4)}' /dev/null` the echo ${myarray} works fine; however, I keep getting following error for the mytitle=.. part: awk: line 1: syntax error at or near { awk: line... (3 Replies)
Discussion started by: littlewenwen
3 Replies

3. Shell Programming and Scripting

Can anyone tell me what's wrong with my script

Hi... I am fed up in file handing with array for comparing.... 1st I want save first 2 columns of file 1 I tried like this,, {getline< "file1";ln=$1; lt=$2}then I read second file's 1st and 2nd column..and saved like this and small calculation and initialization var1 =$1 var2 =$2... (5 Replies)
Discussion started by: Akshay Hegde
5 Replies

4. UNIX for Dummies Questions & Answers

What's wrong on this script?

I get this error on these lines when i run this script:"for i in /home;do file2=`ls -s $i` if ;then ls - s $i fi done (7 Replies)
Discussion started by: kotsos13
7 Replies

5. Shell Programming and Scripting

What's wrong with my script ....

Please see below mentioned my script ... it ran once without any issue .... then after it is not coming out .... please suggest what is wrong? #!/bin/ksh ## if (( ${num_errors} > 0 )); export ACULOG=/home/varshnes/input export num_errors=10 **** Search for 'Start correcting roll up... (7 Replies)
Discussion started by: heyitsmeok
7 Replies

6. Shell Programming and Scripting

Script Gone Wrong

Hello all, so this is a script i did for an assignement, - first option greets the user according to the time after fetching his name - second options isn't implemented - third check the performance according to how many users are using the system - creates a log of names, time and ip of the... (14 Replies)
Discussion started by: ibzee33
14 Replies

7. Shell Programming and Scripting

what is wrong with this script?

Hi I've made a short script but it is not working. Can some pl. help me out in this? ./123.sh #! /usr/bin/ksh # for changing to this directory cd /layered/relational/scripts When I run the above scripts, it doesn't change to the above directory. I don't what is the problem? the... (2 Replies)
Discussion started by: Mike1234
2 Replies

8. UNIX for Dummies Questions & Answers

what is wrong with this script?

Hi, I have this example script which gives error ": unexpected operator/operand". I need the '' brackets for operator precedence. #!/bin/ksh x="abc" y="xyz" z="123" if -a then print "yes" else print "no" fi Thanks (2 Replies)
Discussion started by: rs1969
2 Replies

9. Shell Programming and Scripting

What's wrong with this script

I am trying to create a script but it is giving me errors on Cygwin for the following script. Could someone tell me, what am I doing wrong? choice=1000 echo "choice is $choice" while ; do echo "choice is $choice" echo 'Please select your option:' echo '1. Option 1' echo '2. Option 2'... (3 Replies)
Discussion started by: amitg1980
3 Replies

10. Shell Programming and Scripting

What is wrong with this script?

I keep getting errors messages for the "else" statement at line 81? #!/bin/ksh ######### Environment Setup ######### PATH=/gers/nurev/menu/pub/sbin:/gers/nurev/menu/pub/bin:/gers/nurev/menu/pub/mac :/gers/nurev/menu/adm/sbin:/gers/nurev/menu/adm/bin:/gers/nurev/menu/adm/mac:/ge... (8 Replies)
Discussion started by: heprox
8 Replies
Login or Register to Ask a Question