使用Shell脚本删除文件夹的内容 [英] Deleting content of folder with shell script
本文介绍了使用Shell脚本删除文件夹的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试清空脚本中的文件夹时遇到问题.
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*"
上面写着"rm:Folder1/Folder2/*:没有这样的文件或目录",问题出在哪里?
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.
推荐答案
引号内不会发生全局扩展.
Glob expansion doesn't happen inside quotes.
尝试:
rm -r -- "$DIR"*
(只要确保您在引号后没有空格即可.)
(Just make really sure you don't put a space after the quotes.)
这篇关于使用Shell脚本删除文件夹的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文