| | |
what's wrong with this ?
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2006
Posts: 4
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: May 2004
Posts: 178
Reputation:
Solved Threads: 10
try:
Shell Scripting Syntax (Toggle Plain Text)
# find $1 -type f -exec grep -l -e '/*' -e '//' {} \; | while read file do grep -q ';' $file if [[ $? -ne 0 ]] ; then echo $file | grep -q -e '\.c$' -e '\.h$' if [[ $? -ne 0 ]] ; then mv $file "$file".c fi fi done
![]() |
Similar Threads
- My CD-RW plays but won't burn. What could be wrong?? Help Please? (Storage)
- Retrieve email I sent to the wrong person (Web Browsers)
- Ram voltage wrong?? (Motherboards, CPUs and RAM)
- Am I going about this the wrong way (IT Professionals' Lounge)
- wats wrong with imesh??? (Windows NT / 2000 / XP)
Other Threads in the Shell Scripting Forum
- Previous Thread: Big Favour!!!
- Next Thread: Script to download file using wget
| Thread Tools | Search this Thread |





