script problem
Steven Buehler
steve at ibushost.com
Thu Dec 13 16:56:34 UTC 2007
I have a backup script that I wrote. In it I have a variable that
has listings of directories to back up. Because of some of the sizes of the
directories, and for other reasons, they now want me to break them where I
back them up into multiple files with the name of the directory instead of
all in one file. It would be simple except that I can't find how to get
just the final directory name for each directory.
Example:
DIRSTOBACKUP= "/usr/local/bin
/etc
/home/steve
/usr/local/src"
I can read thru each line of the variable, but unless I use the "split"
function and assign each item in the split, I can't get the last name of the
directory. How can this be accomplished? I guess it might be easier to
find a way to just chop off the first "/" and then replace the rest with "_"
and use that as the backup file name. That way they can also look at the
file name and see what directory it came from if I am able to replace the
"/" characters. But alas, I am not that great at the regular expression
replacement in a string either. I have tried:
DIRSTOBACKUP= "/usr/local/bin
/etc
/home/steve
/usr/local/src"
for name in ${DIRSTOBACKUP[@]}
do
NEWNAME=sed "s/\//_/g" < $name
echo $NEWNAME
done
But that doesn't seem to work. Any ideas?
Thanks
Steve
More information about the redhat-list
mailing list