Search code examples
bashvariablespiping

"Piping" values into Bash variables


I have a Python script that outputs two numbers like so: 1.0 2.0 (that's a space in between the numbers, but it can be a \t, or whatever. I want a bash variable to save the 1.0, and another variable to save the 2.0. Is this possible?

In the past, I've only "piped" one value into a variable like so:

var=`python file.py` ;

but now, I'm interested in saving two values from the python file. Conceptually, similar to:

var1,var2=`python file.py` ; 

Any advice / help?

Thanks!


Solution

  • You can use something like this:

    read var1 var2 < <(python file.py)
    

    The funky <( ) syntax is called process substitution.