我找到了一个安装了 Linux 的inotifywait
机器,所以现在我了解了它的作用和工作原理。:)
这是你需要的吗?
#!/bin/bash
if [ "$1" = "-v" ]; then
Verbose=true
shift
else
Verbose=false
fi
file1="$1"
file2="$2"
$Verbose && printf 'Waiting for %s and %s.\n' "$file1" "$file2"
got1=false
got2=false
while read thisfile; do
$Verbose && printf ">> $thisfile"
case "$thisfile" in
$file1) got1=true; $Verbose && printf "... it's a match!" ;;
$file2) got2=true; $Verbose && printf "... it's a match!" ;;
esac
$Verbose && printf '\n'
if $got1 && $got2; then
$Verbose && printf 'Saw both files.\n'
break
fi
done < <(inotifywait -m -q -e close_write --format %f .)
这会运行一个inotifywait
,但会在一个循环中解析其输出,当看到命令行 ($1
和$2
) 上的两个文件都已更新时,该循环会退出。
请注意,如果一个文件已关闭,然后在第二个文件关闭时重新打开,则此脚本显然不会检测到打开的文件。但这在您的用例中可能不是问题。
请注意,构建解决方案的方法有很多种——我只向您展示了一种。