我有一个shell脚本函数和一个输入参数。在函数中,我嵌入了python多行脚本,它只在python中打印值并导出到shell变量
我尝试将python脚本嵌入到directshell脚本中,但没有将其放入函数中,也没有传递任何输入参数。问题在于如何将shell变量传递给函数中的python脚本
getValues(){
名称=$1
回音$name
python -c '
import ..
value=""
for ..
for key in ..
if "${name}" in key.tags:
value=str(key["tag"])
break;
print(value)'
}你知道吗
导出环境=getValues Environment
出口产品=getValues Product
我期望实际结果像dev/stage(从值打印)一样,但shell中得到的是空字符串
我做错什么了吗
注意:我使用了'`'作为expr来调用代码中的shell表达式,但它没有在这里的代码部分打印出来
你可以让
python
从stdin
读出来输出:
另外,您应该注意到有一个名为
jq
jq的实用程序,它将帮助您读取json文件相关问题 更多 >
编程相关推荐