MKo
MKo

Reputation: 5038

Use echo output as input into a script's stdin

There is a script "X", which depending on input will export some environment variables.

To run "X" within another script "Y", I do the following:

echo "some input" > temp_file
source X < temp_file

Is there a alternative way to do this, without using temporary files?

As I understand in case of pipes a sub-process is created, and by running the following line

echo "some input" | source X

the environment variables can't be set or modified within a current script.

Upvotes: 4

Views: 499

Answers (1)

Blagovest Buyukliev
Blagovest Buyukliev

Reputation: 43508

Use process substitution:

source X < <(echo "some input")

It basically allows you to redirect the input/output of a process to another process as if it were a file.

Upvotes: 5

Related Questions