两个终端运行,一个输入,一个输出
#!/bin/sh
if [ ! -p /root/mytest/testpipe ]
then
/bin/mknod /root/mytest/testpipe p
fi
while :
do
read msg
if [ "$msg" = "" ]
then
continue
else
echo "$msg"
fi
done < /root/mytest/testpipe
#!/bin/sh
tty=`who am i | awk '{print $2}'`
#tty=pts/3
while :
do
echo "enter your name: \c" >/dev/$tty
read name
echo "$name haha"
done > /root/mytest/testpipe
本文介绍了一个简单的Shell脚本实例,该脚本通过创建一个管道来实现双向的数据传递:一个终端负责接收用户输入的名字并发送,另一个终端则读取管道中的信息并做出响应。通过这个例子,读者可以了解到如何使用Shell脚本来进行进程间通信。
1189

被折叠的 条评论
为什么被折叠?



