从Shell脚本导出变量并在Python脚本中访问变量

时间:2019-04-24 15:38:56

标签: python shell environment-variables sh

我试图从我的shell脚本中导出一个变量,然后从我的python脚本中访问它。

    #!/bin/bash
    test="hello, python!!!"
    export test
    python test.py

我的Python脚本如下:

    #!/usr/bin/python
    import os
    text = os.environ.get("test")
    print(text)

获取我的Shell脚本后,在命令行上看不到打印的输出。相反,我看到了:

    shell_script:export:3: not valid in this context: test^M

但是,如果我在获取shell脚本后单独回显或运行python脚本,则能够获得所需的结果。有关一次性完成操作的任何想法?

0 个答案:

没有答案
相关问题