shargo-workflows

Why do I get different results when running shell-script locally and in ARGO?


When I run below shell-script

#!/bin/sh

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

I get expected result

var1
this is the real value

But when I run it in an ARGO-WF like

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

I get different output

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

Why is that? I assume it is due to the backslash. How can this problem solved that I get the same result like running the script locally?

Edit: Double backslash (\\) in ARGO does not solve the problem.


Solution

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