Deleting content of folder with shell script

2020-06-16 08:02发布

Im having problems trying to empty a folder in my script.

This is working in 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/*: No such file or directory", where is the problem?

Im running the script in the same folder as I tried the command.

2条回答
做自己的国王
2楼-- · 2020-06-16 08:50
rm -r $DIR*

That should work, without quotes

查看更多
beautiful°
3楼-- · 2020-06-16 08:54

Glob expansion doesn't happen inside quotes.

Try:

rm -r -- "$DIR"*

(Just make really sure you don't put a space after the quotes.)

查看更多
登录 后发表回答