Deleting content of folder with shell script

老子叫甜甜 提交于 2019-12-09 10:45:36

问题


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.


回答1:


Glob expansion doesn't happen inside quotes.

Try:

rm -r -- "$DIR"*

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




回答2:


rm -r $DIR*

That should work, without quotes



来源:https://stackoverflow.com/questions/10483678/deleting-content-of-folder-with-shell-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!