I'm using fswatch
to keep track of changes to a directory, but would like this process to stop if a certain file exists (with a wildcard). This certain file is created in an alternative directory (not in the tracked directory) by another process (which is generating changes that need to be tracked).
Here's what I tried to do:
while [[ $(shopt -s nullglob; set -- "${file_to_check}"; echo $#) -eq 1 ]]; do
fswatch "${path_to_the_tracked_directory}"
done && echo "Done"
However, this script does not terminate after ${file_to_check}
appears.
The complex bit in the condition is to take care of wildcards as per: Bash check if file exists with double bracket test and wildcards
EDIT:
The complex bit can be simplified to:
while [ $(set -- "${path_to_the_file_to_check}"${file_to_check_with_wildcards}; echo $#) -eq 0 ]; do
fswatch "${path_to_the_tracked_directory}"
done && echo "Done"