从未在bash上编码,但需要紧急事件。对不起,如果这不是常态,但真的想得到一些帮助。根据标准输出消息,bash脚本发出嘟嘟声
我有一些消息被引发到标准输出,根据消息类型(消息是一个字符串与单词“找到”)我需要bash脚本发出哔声。
到目前为止,我已经想出了这个。
output=$(command 1) # getting stdout stream?
while [ true ]; do
if [ "$output" = "found" ]; then # if the stdout has the word "found"
echo $(echo -e '\a') # this makes the beep sound
fi
done
我不知道在哪里/如何添加grep
或awk
命令检查有词串“找到”,只有返回“发现”,因此,在if
条件下它可以检查针对字。
谢谢!
关于钟,稍短,更便携是'printf'\ a''代替'echo $(echo -e'\ a')''。一个简单的'echo -e'\ a''也可以工作;没有必要捕获第一个回声并重新回应它。 – chepner