Removing the contents of a shell script folder

I'm having trouble trying to unload a folder in a script.

This works on my command line:

rm -r Folder1/Folder2/* 

But if in my script I do this:

 DIR="Folder1/Folder2/" rm -r "$DIR*" 

It says: "rm: Folder1 / Folder2 / *: There is no such file or directory", where is the problem?

Im running the script in the same folder in which I tried to execute the command.

+6
source share
2 answers

Glob expansion does not occur inside quotation marks.

Try:

 rm -r -- "$DIR"* 

(Just make sure you don't put a space after the quotation marks.)

+14
source
 rm -r $DIR* 

This should work without quotes

+1
source

Source: https://habr.com/ru/post/915091/


All Articles