【问题标题】:Pass the variables from python script to shell script when python script is being called inside shell script当在 shell 脚本中调用 python 脚本时,将变量从 python 脚本传递到 shell 脚本
【发布时间】:2020-10-02 06:27:48
【问题描述】:

我有一个 shell 脚本 test.sh,它调用了一个 python 脚本 test.py。这个 python 文件生成一个类似列表类型的变量。如何将列表变量从 python 传递到外部 shell 脚本?

【问题讨论】:

    标签: python shell variables subprocess


    【解决方案1】:

    通常我只是将 python 直接包含在 bash 脚本中。

    test=`python -c "print('Hello world!')"`
    echo $test
    

    如果您想运行一个程序,只需让您的程序打印最终值并将该输出分配给一个变量。所以假设你有 test.py 。 . .

    print('Hello world!')
    

    test.sh

    test=`python test.py`
    echo $test
    

    【讨论】: