I am executing a python script from my bash script. The python script outputs 4 lines to stdout. I would like to store the output of these 4 lines in 4 different variables in bash or one array with 4 elements.
When I run my python script byitself I see the 4 lines on stdout:
$ python my_script.py
line1
line2
line3
line4
In my bash script I've done this:
OUTPUT="$(python my_script.py)"
echo "${OUTPUT}"
readarray -t y <<<"$OUTPUT"
After above when I do echo $y I only see output of first line (line1).
How can I use the output of python script as 4 variables or an array?
mapfile -t y < <(python my_script.py)is enough. Now, to output the content of the arrayyto stdout, one field per line:printf '%s\n' "${y[@]}"or to inspect the array:declare -p y.readforbashversions which do not supportreadarrayormaple!