[svlug] Shell Programming Question

Sean Cheng sfmech at yahoo.com
Fri Jul 21 09:34:02 PDT 2000


Hi, I'm learning Shell. I'd like to write a shell script to help me backup
files, but I can't figure out 2 errors.

Here is the script
------
#get the filename
for file in `ls -l|gawk -F" " '{print &9}'`
#separate the sub-filename, if sub-filename matches prt then
#backup the file
subname=`echo $file|cut -d"." -f2`
test "$subname"="prt" && {echo $subname;echo $file}
------
Then the result will be like:

log
spring.log
prt
stylus.prt.7
out
std.out
prt
rearcase.prt.3
...

So it seems that I can't make the correct judgement if the filename matches
a certain pattern, but I don't know what goes wrong.

Another thing is that I can't write
test "$subname"="prt"     as
["$subname"="prt"]
because I'll get the error message like

./backup: [prt=prt]: command not found
./backup: [drw=prt]: command not found

I also can't figure why. My OS is RedHat 6.0

Please help.

Sean Cheng





More information about the svlug mailing list