Hi all,
here is my shell script.
Code:
backup_files()
{
FSource=$1
if [ $ABSOLUTE = "1" ]; then
FTarget="$BACKUPPATH/`date '+%Y%m%d'`"
desDir = "`echo $FILEPATH | sed -e 's/\/.*/ /'`"
TmpTarget = $FTarget/$desFir
if [ ! -d $TmpTarget ]; then
mkdir -p $TmpTarget
fi
cp $DATAPATH/$FSource $Tmptarget/.
else
FTarget="$BACKUPPATH/`date '+%Y%m%d'`"
TmpTarget = $FTarget/$FILEPATH
TmpTrgt = "`cd $TmpTarget | cd .. | pwd`"
if [ ! -d $TmpTrgt ]; then
mkdir -p $TmpTrgt
fi
cp $FSource $TmpTrgt/.
fi
}
what i want to do is :
let say the $FILEPATH = "/tmp/200/readme"
i want the desDir to capture only the "readme" by detect the last "/"
i write the statement like this:
desDir = "`echo $FILEPATH | sed -e 's/\/.*/ /'`"
But failed to get the value, it return empty.
Can anyone teach me how to use the sed or awk? thanks.