gpt4 book ai didi

bash:对于文件是否存在?

转载 作者:行者123 更新时间:2023-11-29 09:12:10 24 4
gpt4 key购买 nike

所以,

for f in *.c; do echo "That $f is the best C code I have ever seen"; done

如果没有c文件,会很乐意打印

That *.c is the best C code I have ever seen

这是不可取的。如果没有 c 文件,是否有一种优雅的方式来修复/表达我想完全跳过循环的事实?

最佳答案

设置nullglob选项。如果没有匹配,则扩展将为空。

shopt -s nullglob
for f in *.c; do …

请注意,这是一个特定于 bash 的构造,它不会在普通 sh 下工作。

关于bash:对于文件是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15935806/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com