The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
what is wrong with this script? rs1969 UNIX for Dummies Questions & Answers 2 11-15-2007 07:16 AM
What's wrong with this script amitg1980 Shell Programming and Scripting 3 11-12-2007 07:00 PM
what is wrong with this script? hankooknara Shell Programming and Scripting 8 06-09-2007 12:33 PM
What is wrong with this script? heprox Shell Programming and Scripting 8 11-16-2006 05:43 AM
what is wrong with this script? circleW Shell Programming and Scripting 2 09-28-2004 08:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2003
Lem2003 Lem2003 is offline
Registered User
  
 

Join Date: May 2003
Posts: 14
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 (permalink)  
Old 05-28-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
I was trying to look at this, but it's late and my eyes are crossing.

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 (permalink)  
Old 05-28-2003
Lem2003 Lem2003 is offline
Registered User
  
 

Join Date: May 2003
Posts: 14
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 (permalink)  
Old 05-28-2003
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
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 (permalink)  
Old 05-28-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
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 (permalink)  
Old 05-28-2003
marlondouglas marlondouglas is offline
Registered User
  
 

Join Date: Apr 2003
Location: Honduras
Posts: 1
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 (permalink)  
Old 05-29-2003
Lem2003 Lem2003 is offline
Registered User
  
 

Join Date: May 2003
Posts: 14
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...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0