bash – 从shell脚本检查目录是否包含文件

前端之家收集整理的这篇文章主要介绍了bash – 从shell脚本检查目录是否包含文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
从shell脚本,如何检查目录是否包含文件

类似的东西

if [ -e /some/dir/* ]; then echo "huzzah"; fi;

但如果目录包含一个或多个文件(上面的一个只适用于完全0或1个文件)。

到目前为止,解决方案使用ls。这里有一个bash解决方案:
#!/bin/bash
shopt -s nullglob dotglob     # To include hidden files
files=(/some/dir/*)
if [ ${#files[@]} -gt 0 ]; then echo "huzzah"; fi
原文链接:https://www.f2er.com/bash/392222.html

猜你在找的Bash相关文章