使用yq编辑yaml文件(--in-place,-i标志)

使用yq编辑yaml文件(--in-place,-i标志),yaml,edit-in-place,yq,Yaml,Edit In Place,Yq,yq 2.12.0版的“原地编辑”标志有一个大问题。 我们正在尝试更新.yaml脚本中某个变量的值。前一个看起来像这样 authentication: anonymous: enabled: false 但是我们想要这个 authentication: anonymous: enabled: true 我们试着逃跑 sudo yq -y ".authentication.anonymous.enabled |= true" sample.yml

yq 2.12.0版的“原地编辑”标志有一个大问题。 我们正在尝试更新.yaml脚本中某个变量的值。前一个看起来像这样

authentication:
  anonymous:
    enabled: false

但是我们想要这个

authentication:
  anonymous:
    enabled: true
我们试着逃跑

sudo yq -y ".authentication.anonymous.enabled |= true" sample.yml
但它会覆盖整个文件并使其为空:/ 我们目前的解决办法是运行

sudo yq -y ".authentication.anonymous.enabled |= true" sample.yml > newfile.yml
sudo cp newfile.yml sample.yml

因此,基本上我们创建我们想要的正确输出,但只需将其推送到一个新文件中,然后将新内容复制到旧文件中(我知道这是一个巨大的考验)。必须有更好的方法来实现这一点……有人能告诉我如何正确使用yq--in-place标志编辑文件吗?

也许可以尝试升级,因为2.12.0是当前4.7.1的两个主要版本,它确实有
-i
您使用的是Python yq而不是Go版本mikefarah/yq吗?