将事件和数据发送到bash脚本

时间:2016-08-27 04:05:04

标签: linux bash

我需要有一个bash脚本等待来自另一个数据的数据 是否有我可以实现的原生Linux方式,最好不使用可能变得陈旧的文件?

2 个答案:

答案 0 :(得分:1)

我最终解决这个问题的方法是使用fifo管道。

e.g。 source.sh

#!/bin/bash

if ! [ -p "pipe" ]; then
  mkfifo -m 0600 "pipe"
fi

echo "hello world" > "pipe"

dest.sh

#!/bin/bash

if ! [ -p "pipe" ]; then
  mkfifo -m 0600 "pipe"
fi

MYVAR=$(<"pipe")
echo $MYVAR

因为写入和读取块,所以在发送或读入数据之前,每个脚本都不会继续。

答案 1 :(得分:0)

是否可以在脚本中使用Subshell?虽然我个人对此没有任何经验,但您可能想尝试其他方法。