what's wrong with this ?

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2006
Posts: 4
Reputation: yaeli_17 is an unknown quantity at this point 
Solved Threads: 0
yaeli_17 yaeli_17 is offline Offline
Newbie Poster

what's wrong with this ?

 
0
  #1
Feb 8th, 2007
Hi.

I need to write a short script that's looking for a C files in a directory (based on whether it has a semicolon in it and a comment // or /*), check if the file ends with .c and rename it if it doesn't.
I'm pretty much new at this. i wrote this script but it doesn't seem to create the new file with the .c extension.

any input on why would be greatly apreciated.

#!/bin/bash
listOfFiles=`ls $1`
for file in $listOfFiles
do
semi=`grep ";" "$1/$file"`
slash=`grep "//" "$1/$file"`
if [ "$semi" != "" ]
then
if [ "$slash" != "" ]
then
extension=`echo $file | grep ".c$|.h$"`
if [ "extension" == "" ]
then
mv $1/$file $1/$file.c
fi
fi
fi
done
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 178
Reputation: jim mcnamara is on a distinguished road 
Solved Threads: 10
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: what's wrong with this ?

 
0
  #2
Feb 13th, 2007
try:
Shell Scripting Syntax (Toggle Plain Text)
  1. #
  2. find $1 -type f -exec grep -l -e '/*' -e '//' {} \; |
  3. while read file
  4. do
  5. grep -q ';' $file
  6. if [[ $? -ne 0 ]] ; then
  7. echo $file | grep -q -e '\.c$' -e '\.h$'
  8. if [[ $? -ne 0 ]] ; then
  9. mv $file "$file".c
  10. fi
  11. fi
  12. done
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC