简体   繁体   English

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

[英]bash convert json to string and pass as argument to python script

Hello how can I read a json from filesystem with bash and pass the string as an argument to a python script?您好,如何使用 bash 从文件系统读取 json 并将字符串作为参数传递给 python 脚本? I tried this.我试过这个。 But it does not work但它不起作用

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

Why eliminate the newlines?为什么要消除换行符?

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

Or if you really need them gone,或者如果你真的需要它们消失,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM