如何使用bash测试目录中文件的存在
if ... ; then
echo 'Found some!'
fi为了明确起见,我不想测试是否存在特定的文件。我想测试一个特定的目录是否包含任何文件。
我跟着:
(
shopt -s dotglob nullglob
existing_files=( ./* )
if [[ ${#existing_files[@]} -gt 0 ]] ; then
some_command "${existing_files[@]}"
fi
)使用该数组可避免两次读取文件列表的竞争条件。
发布于 2012-01-19 05:35:09
#!/bin/bash
if [ -e $1 ]; then
echo "File exists"
else
echo "Files does not exist"
fi https://stackoverflow.com/questions/8921441
复制相似问题