具有多个 env 运算符的 yq 查询
yq query with multiple env operator
给定以下 example.yaml 定义:
shop:
europe:
germany:
shopA: shopBAddress
asia:
thailand:
shopB:
address: shopBAddress
我尝试使用 env
运算符访问 shop.europe.germany
路径。
但是当我这样做时出现错误:
location=europe country=germany yq e '.shop.[env(location)].[env(country)]' example.yaml
Error: Bad expression, please check expression syntax
location=europe country=germany yq e '.shop.[env(location)][env(country)]' exmaple.yaml
Error: Cannot index array with 'germany' (strconv.ParseInt: parsing "germany": invalid syntax)
我做错了什么?
你的想法是正确的,但是在两个 env(..)
表达式之间或前面的一个表达式之间,你不需要 .
运算符,即下面应该可以工作(在版本 4.11.2 上验证)
location=europe country=germany yq e '.shop[env(location)][env(country)]' yaml
给定以下 example.yaml 定义:
shop:
europe:
germany:
shopA: shopBAddress
asia:
thailand:
shopB:
address: shopBAddress
我尝试使用 env
运算符访问 shop.europe.germany
路径。
但是当我这样做时出现错误:
location=europe country=germany yq e '.shop.[env(location)].[env(country)]' example.yaml
Error: Bad expression, please check expression syntax
location=europe country=germany yq e '.shop.[env(location)][env(country)]' exmaple.yaml
Error: Cannot index array with 'germany' (strconv.ParseInt: parsing "germany": invalid syntax)
我做错了什么?
你的想法是正确的,但是在两个 env(..)
表达式之间或前面的一个表达式之间,你不需要 .
运算符,即下面应该可以工作(在版本 4.11.2 上验证)
location=europe country=germany yq e '.shop[env(location)][env(country)]' yaml