Short answer: use a for loop, subshell invocation (see assigning value to shell variable using a function return value from Python), and set the IFS to just newline.
See the following demonstrations:
First, create a python program that prints a variable-length list of strings:
$ cat > stringy.py list = [ 'the quick brown fox', 'jumped over the lazy', 'dogs' ] for s in list: print s import sys sys.exit(0) <ctrl-D>
Demonstrate that it works:
$ python stringy.py the quick brown fox jumped over the lazy dogs
Launch ksh:
$ ksh
Example #1: for loop, invoking subshell, standard IFS, no quoting:
$ for line in $(python stringy.py) ; do echo "$line" ; done # Edited: added double-quotes the quick brown fox jumped over the lazy dogs
Example #2: for loop, invoking subshell, standard IFS, quoting:
$ for line in "$(python stringy.py)" ; do echo "$line" ; done # Edited: added double-quotes the quick brown fox jumped over the lazy dogs
Example #3: for loop, invoking subshell, no quoting, IFS set to just newline:
$ IFS=$'\n' $ echo $IFS $ for line in $(python stringy.py) ; do echo $line ; done # Edited: added double-quotes the quick brown fox jumped over the lazy dogs
Example #3 demonstrates how to solve the problem.