Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with a simple script

Status
Not open for further replies.

unixbeginner

Programmer
Feb 11, 2007
3
CA
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:
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
 
alright i think the problem was i didn't put a $ infront of the extension variable :-S
ignore, and thanks :)
 
so now i have this other problem.

in this script i'm ment to preform checksums on files and save only the modified files in a tarball directory called Backups, only if the names of the files do not end with .var or .tar or .z and whose name is not contained in a file called "%nobackup"

I wrote this but keep getting an error saying "Backups is a directory" (which i created to test this). and when i don't it complains that the directory is missing.
am i using the tar command correctly?
what could be wrong with this?
thanks in advance !

Code:
#!/bin/bash
files=`ls`
for file in $files
do
        extension=`echo "$file" | grep ".var$|.tar$|.z$"`
        ckBackup=`grep "$file" "%nobackup"`
        if [ "$extension" == "" -a "$ckBackup" == "" ]
        then
                checksum=`cksum "$file"`
                specialFile=`grep "$checksum" "$1"`
                        if [ "$specialFile" == "" ]
                        then
                                echo "$checksum" >> "$1"
                                tar -cf "./Backups/$file.$$.tar" "$file"
                        fi
        fi
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top