2
我有一個腳本不工作:shell腳本:`[[`如預期
ENABLE_SYSLOG=true
test -r /etc/default/inotifywait && . /etc/default/inotifywait || exit 99
test -d $INOTIFY_FOLDER || exit 100
inotifywait -mrq -e ATTRIB --format '%w%f' "$INOTIFY_FOLDER" | while IFS= read -r FILE
do
if [ -f $FILE ];then
# If file
if [ `stat -c %a $FILE` != "664" ] ;then
CHMOD_LOG=$(chmod -v 664 "$FILE")
[[ "$ENABLE_SYSLOG" = true ]] && logger -t inotifywait -p user.info "$CHMOD_LOG" &
fi
else
# If directory
if [ `stat -c %a $FILE` != "2775" ] ;then
CHMOD_LOG=$(chmod -v 2775 "$FILE")
[[ "$ENABLE_SYSLOG" = true ]] && logger -t inotifywait -p user.info "$CHMOD_LOG" &
fi
fi
done
爲什麼我的病情
[[ "$ENABLE_SYSLOG" = true ]] && logger -t inotifywait -p user.info "$CHMOD_LOG"
不工作?
如果我刪除
[[ "$ENABLE_SYSLOG" = true ]] &&
然後一切都很好。
我嘗試刪除&符號(&),嘗試其他條件(如您在示例中所見),嘗試是否代替[[ - 但都是徒勞的。
任何條件是不行的
你可以說:'「$ ENABLE_SYSLOG」&& ...' – anubhava
哦謝謝。這太棒了 – vskubriev
雖然這看起來很聰明,但這可能不是一個好主意。你應該嘗試找出爲什麼你的嘗試不起作用,因爲它應該。你使用的是什麼版本的'bash'?你如何運行腳本? –