使用 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/*: No such file or directory",问题出在哪里?
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屋!
查看全文