0

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?

4
  • What sort of data? Is a pipe appropriate: another-script | one-bash-script? Commented Aug 27, 2016 at 4:10
  • 3
    you don't have to chain them either with named pipes, check for mkfifo Commented Aug 27, 2016 at 4:13
  • Chaining won't work. It's actually a complex service dependency in runit. But it's not enough to check if the other service is running. It outputs data that the other is dependant on. Commented Aug 27, 2016 at 4:14
  • I'm looking at mkfifo now. Commented Aug 27, 2016 at 4:15

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

3 Comments

Unfortunately not.
Did you solve your problem ? I am also very much interested in this particular questions.
I did, I'll post an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.