Passing python array to bash script (and passing bash variable to python function)

后端 未结 5 759
感情败类
感情败类 2021-01-02 16:27

I have written a Python module which contains functions that return arrays. I want to be able to access the string arrays returned from the python module, and iterate over i

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-02 16:52

    This helps too. script.py:

     a = ['String','Tuple','From','Python']
    
        for i in range(len(a)):
    
                print(a[i])
    

    and then we make the following bash script pyth.sh

    #!/bin/bash
    
    python script.py > tempfile.txt
    readarray a < tempfile.txt
    rm tempfile.txt
    
    for j in "${a[@]}"
    do 
          echo $j
    done
    

    sh pyth.sh

提交回复
热议问题