Bash: 查找不存在给定文件的任何子目录
Bash: Find any subdirectories without a given file present
我想知道我的文件是否存在于以下任何子目录中。子目录是在我的 shell 脚本的上述步骤中创建的,下面的代码总是告诉我文件不存在(即使它存在),我也希望打印路径。
#!/bin/bash
....
if ! [[ -e [ **/**/somefile.txt && -s **/**/somefile.txt ]]; then
echo "===> Warn: somefile.txt was not created in the following path: "
# I want to be able to print the path in which file is not generated
exit 1
fi
我知道文件名是somefile.txt,要在所有子目录中创建,但是子目录名称变化很大..所以globbing.
#!/bin/bash
shopt -s extglob ## enable **, which by default has no special behavior
for d in **/; do
if ! [[ -s "$d/somefile.txt" ]]; then
echo "===> WARN: somefile.txt was not created (or is empty) in $d" >&2
exit 1
fi
done
我想知道我的文件是否存在于以下任何子目录中。子目录是在我的 shell 脚本的上述步骤中创建的,下面的代码总是告诉我文件不存在(即使它存在),我也希望打印路径。
#!/bin/bash
....
if ! [[ -e [ **/**/somefile.txt && -s **/**/somefile.txt ]]; then
echo "===> Warn: somefile.txt was not created in the following path: "
# I want to be able to print the path in which file is not generated
exit 1
fi
我知道文件名是somefile.txt,要在所有子目录中创建,但是子目录名称变化很大..所以globbing.
#!/bin/bash
shopt -s extglob ## enable **, which by default has no special behavior
for d in **/; do
if ! [[ -s "$d/somefile.txt" ]]; then
echo "===> WARN: somefile.txt was not created (or is empty) in $d" >&2
exit 1
fi
done