unixbeginner
Programmer
i'm knew to this forum, and new in shell scripting, and desperately need your help on this.
we're ment to write a small script that is searching a directory (only argument given) for C files (determined by a semicolon AND a comment either // or /*), checks if the file has a .c extension, and renames it if it does not have it.
Now i've written this so far. but it doesn't seem to create a .c file when its supposed to. Can anyone tell me what can be the problem with this?
Any help would be greatly appreciated.
this is what i've written so far:
we're ment to write a small script that is searching a directory (only argument given) for C files (determined by a semicolon AND a comment either // or /*), checks if the file has a .c extension, and renames it if it does not have it.
Now i've written this so far. but it doesn't seem to create a .c file when its supposed to. Can anyone tell me what can be the problem with this?
Any help would be greatly appreciated.
this is what i've written so far:
Code:
#!/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