为什么我在本地和 ARGO 中运行 shell 脚本时得到不同的结果?

问题描述 投票:0回答:1

当我在 shell 脚本下运行时

#!/bin/sh

var1="this is the real value"
a="var1"
echo $a
eval "b=\$$a"
echo $b

我得到了预期的结果

var1
this is the real value

但是当我在 ARGO-WF 中运行它时

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: shell-example-
spec:
  entrypoint: shell-script
  templates:
    - name: shell-script
      container:
        image: alpine/curl:latest
        command: [sh, -c]
        args:
          - |
            var1="this is the real value"
            a="var1"
            echo $a
            eval "b=\$$a"
            echo $b

我得到不同的输出

shell-example-9q6zd-xv4d8: var1
shell-example-9q6zd-xv4d8: var1

这是为什么呢?我认为这是由于反斜杠造成的。这个问题如何解决才能得到与本地运行脚本相同的结果?

编辑:ARGO 中的双反斜杠 (\) 无法解决问题。

sh argo-workflows
1个回答
0
投票

eval "b=\${$a}"
eval 'b=$'"$a"

© www.soinside.com 2019 - 2024. All rights reserved.