[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

RE: script problem



Have you tried `basename` ? 

-----Original Message-----
From: redhat-list-bounces redhat com
[mailto:redhat-list-bounces redhat com] On Behalf Of Steven Buehler
Sent: Thursday, December 13, 2007 10:57 AM
To: 'General Red Hat Linux discussion list'
Subject: script problem

	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

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request redhat com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]