不能 rm 或 cp 文件名中带有通配符

unf*_*nfa 2 bash quoting wildcards

我的脚本中有这样一行:

rm "$TEMP_DIR/*.txt"
Run Code Online (Sandbox Code Playgroud)

此输出失败:

rm: cannot remove 'temp/*.txt': No such file or directory
Run Code Online (Sandbox Code Playgroud)

我不明白为什么那不起作用。我究竟做错了什么?

unf*_*nfa 6

因为您在命令中使用引号,所以rm认为您想要一个带有文字*字符的文件名,它不会将其扩展为通配符。尝试不加引号以匹配所有以以下结尾的文件.txt

rm "$TEMP_DIR"/*.txt
Run Code Online (Sandbox Code Playgroud)