I face the following problem, which looks like a bug (or maybe am I the bug):
I have a loop:
#!/bin/bash
#
TARGET=/sd/REMOTE_BACKUP
LOGDIR=/sd
DEBUG=:
# Init daily information (reset on each run and at midnight)
TODAY=$(date +%Y-%m-%d)
TODAYCOUNT=0
TODAYDELTA=0
RECOMPUTESTORAGE() {
echo 123 456
}
inotifywait -m -e close_write -e moved_to -e delete --recursive --format "%w %f" $TARGET/ \
| while read DIRNAME FILENAME EXTRA
do
tput el
$DEBUG "DIRNAME=$DIRNAME FILENAME=$FILENAME"
# 3.6 - Exit request
[[ -f $TARGET/.exit ]] && \
echo "${BOLD}Exit${SGR0} request received..." && \
rm -v $TARGET/.exit && \
exit
# 3.7 - Recompute storage request
[[ -f $TARGET/.recompute ]] && \
read FULL USED <<<$( RECOMPUTESTORAGE ) && \
DELTA=$USED && \
rm -v $TARGET/.recompute && \
continue
if [ "${FILENAME}" == "" ]; then
# Simply skip, but take the opportunity to refresh
echo "${FILENAME} REMoVED"
else
echo -e "\nUnencrypted file $FILENAME *NOT* externalized"
fi
echo -n -e "\rWaiting event...${EL}\r"
done \
| tee ${LOGDIR}$(basename $0).log
But on execution time, after echoing "found non-empty $TARGET", the execution continues with the echo "proceed with the loop" instead of branching (ugly word I know) to the next read.
Based on Bash's manual the "continue" statement should jump to the next iteration, ignoring the rest of the loop body.
Can you explain why this does not correctly occur?
Thank you
Ouput:
$ sudo bash /tmp/b
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.
removed '/sd/REMOTE_BACKUP/.recompute'
Unencrypted file .recompute *NOT* externalized
Waiting event...
&& continuejust doesn't work. If you put your conditions in one if statement and use; then continuethat should work.$DEBUGintoecho?&& continueworks correctly in a simple while loop (easy to test).$DELTAis assigned a value in a right hand side of a pipe, i.e. in a subshell, i.e. it won't retain the value outside the loop.