$ cat app.sh #应用程序的代码 #!/bin/bash
FIFO=fifo_test while :; do CI=`cat $FIFO` #CI --> Control Info case $CI in 0) echo "The CONTROL number is ZERO, do something ..." ;; 1) echo "The CONTROL number is ONE, do something ..." ;; *) echo "The CONTROL number not recognized, do something else..." ;; esac done $ cat control.sh #控制程序的代码 #!/bin/bash
FIFO=fifo_test CI=$1
[ -z "$CI" ] && echo "the control info should not be empty" && exit
echo $CI > $FIFO $ chmod +x app.sh control.sh #修改这两个程序的可执行权限,以便用户可以执行它们 $ ./app.sh #在一个终端启动这个应用程序,在通过./control.sh发送控制码以后查看输出 The CONTROL number is ONE, do something ... #发送1以后 The CONTROL number is ZERO, do something ... #发送0以后 The CONTROL number not recognized, do something else... #发送一个未知的控制码以后 $ ./control.sh 1 #在另外一个终端,发送控制信息,控制应用程序的工作 $ ./control.sh 0 $ ./control.sh 4343
|