#WithExec Behaviour

1 messages · Page 1 of 1 (latest)

tight compass
#

Can someone explain this behaviour to me as I don't understand how this works under the hood:

        WithSecretVariable("GITHUB_TOKEN", client.Host().EnvVariable("GITHUB_TOKEN").Secret()).
        WithExec([]string{"printenv"}). // will display the token and its value 
        WithExec([]string{"echo", "$GITHUB_TOKEN"}). // won't echo the token
        WithExec([]string{"sh", "-c", "echo $GITHUB_TOKEN"}). // will echo the token
        Stdout(ctx)

Why do I need to run the shell command myself to get a secret to be displayed in the terminal?

thin birch
#

👋 Ronan! echo won't show anything because echo is not a linux command. It's a shell builtin

#

so you need a shell like sh, bash, etc for echo to work

tight compass
#

🥹 Okay I'm gonna go hide now. Thanks!

#

Dumb question but what is it using if I don't pass in sh -c

thin birch
#

if your echo withExec succeeds but shows "$GITHUB_TOKEN" instead it's because echo doesn't actually print env variables.

When you do echo $FOO in the shell of your local machine what actually expands the $FOO variable is the shell itself, not the echo command. echo is not a aware of env variables, the shell is. echo just echoes back whatever argument you send to it. The one who actually resolves the env variable name to its value is the shell, not echo

tight compass
#

👍 Makes a lot of sense. Appreciate the explanation.