I am trying to write a BASH script which will delete recursively all files in a directory.
When I write in console rm -rf /home/dir/dir/*
, it works great, but I can't do it using variables.
VAR="/home/dir/dir"
rm -rf "$VAR"/*
This code didn't work for me.
Update.
It is really really weird. I've tried to delete quotation marks, but it doesn't work.
Here is my whole file:
#### VARIABLES
LOGS_PATH="~/Документы/tellbot_work/tellbot-autotest/mega-test/Reports/Mega\ test"
#### End of variables
#### FUNCTIONS
delete_logs()
{
rm -rf $LOGS_PATH/*
echo "Logs from $LOGS_PATH were deleted"
}
#### End of functions
#### MAIN
delete_logs
#### End of main
In output it shows a right path to the files...
You can avoid the tilde-problem by just using variable home. So just write
LOGS_PATH="${HOME}/Документы/tellbot_work/tellbot-autotest/mega-test/Reports/Mega test"
instead of
LOGS_PATH="~/Документы/tellbot_work/tellbot-autotest/mega-test/Reports/Mega test"
and the command
rm -rf "$LOGS_PATH"/*
Should be usable again.