I need to have one bash script wait on a piece of data from another.
Is there a native Linux way that I can accomplish that, preferably without the use of files which can become stale?
2 Answers
The way I solved this in the end was to use fifo pipes.
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
Because writing and reading blocks, each script will not proceed until either the data is sent or read in.
Comments
Is it possible to use the Subshell in the scripting? Though I personally do not have any experience with it thought you might want to try other approaches.
another-script | one-bash-script?mkfifo