case在查看尾部輸出時,我找不到我的陳述句不起作用的原因。
tail -F -n1 /var/log/pihole.log |
while read input; do
echo "$input" | hexdump -C # just to physically compare the output
case $input in
cached|blacklisted|blocked)
echo "We have a match!";;
*)
echo "No match!"
esac
done
這總是回傳No match!,即使字串中$input。
:~ $ ./pihole_test.sh
00000000 4a 61 6e 20 31 20 31 31 3a 35 35 3a 35 38 20 64 |Jan 1 11:55:58 d|
00000010 6e 73 6d 61 73 71 5b 36 39 36 5d 3a 20 65 78 61 |nsmasq[696]: exa|
00000020 63 74 6c 79 20 62 6c 61 63 6b 6c 69 73 74 65 64 |ctly blacklisted|
00000030 20 70 6c 61 79 2e 67 6f 6f 67 6c 65 2e 63 6f 6d | play.google.com|
00000040 20 69 73 20 30 2e 30 2e 30 2e 30 0a | is 0.0.0.0.|
0000004c
No match!
uj5u.com熱心網友回復:
代替
cached|blacklisted|blocked)
和
*cached*|*blacklisted*|*blocked*)
匹配子串。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/400941.html
上一篇:處理bash腳本中的特殊字符
