我试图在yq中传递bash变量。
test.yml
configuration:
Properties:
corporate-url: https://stackoverflow.com/temp = '.configuration.Properties.corporate-url'
export $temp
Value1=$(yq '.[env($temp)]' test.yml)预期产出:
https://stackoverflow.com/但是我得到了这个错误(实际输出)。
Error: Value for env variable '$variable1' not provided in env()请注意:我正在尝试获取企业-url值,使用bash变量,约束条件是,当temp的值发生变化时,不能在yq中直接传递字符串,因为这个代码段运行在一个for循环中,该循环每次都会更改temp的值,因此无法为特定值编写硬代码。
参考YQ文档: https://mikefarah.gitbook.io/yq/operators/env-variable-operators
ApisDraft文件夹包含多个yml文件
ApisDraft=$(find drafts/* -maxdepth 1 -type f)
for ApiFixOrgsTags in $ApisDraft
do
my_var=$(yq '.securityDefinitions.[].tokenUrl' $ApiFixOrgsTags)
ConfigProper='.configuration.Properties.'
CatelogProper='.configuration.catalogs.[].Properties.'
variable1=$ConfigProper${my_var}
variable2=$CatelogProper${my_var}
# to remove white all spaces
variable1= echo $variable1 | sed -E 's/(\.) */\1/g'
variable2= echo $variable2 | sed -E 's/(\.) */\1/g'
export $variable1
export $variable2
Value1=$(yq "$variable1" $ApiFixOrgsTags)
Value2=$(yq '.[env($variable2)]' $ApiFixOrgsTags)
done发布于 2022-10-03 19:20:02
在这种情况下,您不需要将其放在环境中。让shell展开它,使yq只看到变量的值:
yq "$temp" test.yml # => https://stackoverflow.com/https://stackoverflow.com/questions/73939413
复制相似问题