bash - 如果使用 Bash 目录为空,则不显示结果

标签 bash shell

例如,在空目录中尝试以下命令:

$ for i in *; do echo $i; done
*

有没有办法抑制*的打印输出?

最佳答案

设置nullglob

shopt -s nullglob
for i in *; do echo "$i"; done

关于bash - 如果使用 Bash 目录为空,则不显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20576593/

相关文章:

当前行的 Linux shell 脚本 livecopy

bash - 没有 BASH 的 UNIX shell 有什么好处?

shell - 逐行读取 python 的 shell 输出

bash - 如何制作 bash 脚本来检查程序或库是否存在

bash - 读取管道中的变量时会发生什么?

unix - shell命令相当于按键盘上的回车键

shell - Shell 脚本中的循环变量和 `unset`

bash - 如果远程位置存在相同的现有文件夹名称,则将文件夹中的所有文件移动到新位置

bash - 将方法传递给heredocs

Bash 解析 if ["$s1"= ="s2"] 作为命令