bash将json转换为字符串并作为参数传递给python脚本

时间:2020-10-01 14:53:10

标签: python bash shell

您好,我如何使用bash从文件系统中读取json并将字符串作为参数传递给python脚本? 我试过了但这不起作用

config=`cat test.json | tr '\n' ' '`
python3 script.py\
    --config $config  \

1 个答案:

答案 0 :(得分:2)

为什么要消除换行符?

python3 script.py --config "$(<test.json)"

或者如果您真的需要它们,

python3 script.py --config "$( tr "\n" ' ' < test.json)"
相关问题