Hi Team,
I would like to take backup of a folder in case if the folder already exist it should display as folder exists
-----------------------------------------------------------------------------------------------
dt=`date +%F`
present='/tmp/home_$dt'
if [ ! -d "$present" ] ; then
`cp -pr /home/dtail/testing/global/script/home /tmp/home_$dt`
sleep 8
else
echo "Already /home folder present "
fi
-------------------------------------------------------------------------------------------------
even though the backup folder created its not displaying the message Already folder present
query about shell
-
- Posts: 519
- Joined: 2012/06/26 14:20:47
Re: query about shell
Replace the single quotes around /tmp/home_$dt with double quotes (") so that $dt gets expanded.
Remove the backticks around the cp.
Remove the backticks around the cp.
Re: query about shell
Because single quotes are interpreted literally i.e. variables aren't expanded....
Code: Select all
dt="$(date +%F)"
present="/tmp/home_$dt"
if [ ! -d "$present" ]; then
cp -pr "/home/dtail/testing/global/script/home" "/tmp/home_$dt"
sleep 8
else
echo 'The /home folder is already present!'
fi