script problem

Steven Buehler steve at ibushost.com
Thu Dec 13 17:26:19 UTC 2007


Thank You.  I don't think I have ever even heard of that one before.
I was playing around with sed more since I first sent to the list and
figured out how to replace all of the "/" characters.
----------------
#!/bin/sh
DIRSTOBACKUP= "/usr/local/bin
/etc
/home/steve
/usr/local/src"

For name in ${DIRSTOBACKU[@]}
do
NEWNAME=`echo $name | sed s:/:_:g`
NEWNAME=`echo $NEWNAME | sed s:_::`
echo $NEWNAME
done
------------
That would give me the output of:
etc
home_steve
usr_local_src

And from there I can easily work with that.  So I can now have my scripts
either use basename or sed to do what I need depending on how the boss wants
the file name.

Thanks to all.
> -----Original Message-----
> From: redhat-list-bounces at redhat.com [mailto:redhat-list-
> bounces at redhat.com] On Behalf Of Kristoffer Knigga
> Sent: Thursday, December 13, 2007 11:13 AM
> To: General Red Hat Linux discussion list
> Subject: RE: script problem
> 
> Have you tried `basename` ?
> 
> -----Original Message-----
> From: redhat-list-bounces at redhat.com
> [mailto:redhat-list-bounces at 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 at 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
> ______________________________________________________________________
> 
> --
> redhat-list mailing list
> unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
> https://www.redhat.com/mailman/listinfo/redhat-list




More information about the redhat-list mailing list