如果一个 glob 模式没有匹配到任何文件,
那么,在
bash
将会返回字面上的模式。bash-4.1# echo nonexistent-file-*
nonexistent-file-*
bash-4.1#
您可以通过设置 nullglob
shell 选项来修改默认行为,因此如果没有匹配项,您将得到一个空字符串:
bash-4.1# shopt -s nullglob
bash-4.1# echo nonexistent-file-*
bash-4.1#
那么,在
ash
中有相应的选项吗?bash-4.1# ash
~ # echo nonexistent-file-*
nonexistent-file-*
~ # shopt -s nullglob
ash: shopt: not found
~ #
test "$(echo file-*)" = "file-*" && true || <something using files>
解决了这个问题。 - Mattias Wadman