Use echo output as input in stdin script

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

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

echo "some input" > temp_file source X < temp_file 

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

As I understand it, in the case of pipes, a subprocess is created and the next line is executed

 echo "some input" | source X 

environment variables cannot be set or changed in the current script.

+4
source share
1 answer

Use process substitution :

 source X < <(echo "some input") 

Basically, this allows you to redirect the input / output of a process to another process, as if it were a file.

+5
source

Source: https://habr.com/ru/post/1395012/


All Articles