1

From the documentation of github actions:

outputs:
random-number:
  description: "Random number"
  value: ${{ steps.random-number-generator.outputs.random-id }}
runs:
  using: "composite"
  steps:
    - id: random-number-generator
    run: echo "::set-output name=random-id::$(echo $RANDOM)"
    shell: bash

In the run clause 2 echos exist, one for the whole line and one echo $RANDOM

Isn't the second echo unnessecary?

On my computer

echo "::set-output name=random-id::$(echo $RANDOM)"

outputs:

::set-output name=random-id::28124

while

echo "::set-output name=random-id::$RANDOM"

outputs

::set-output name=random-id::28123

so both works.

So why is $(echo $RANDOM) needed ?

1
  • who says it's needed? Commented Aug 8, 2022 at 7:09

1 Answer 1

1

This comes from Metadata syntax / outputs for composite actions and is not strictly needed.

The documentation mentions:

If you need to pass environment variables into an action, make sure your action runs a command shell to perform variable substitution.

By using $(echo $RANDOM), you "force" said variable substitution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.