Skip to content

[Bug] echo string with escaped newlines fails #25469

Answered by Simran-B
MrSkwiggs asked this question in Actions
Discussion options

You must be logged in to vote

To avoid issues with multiple lines or command substitution, the documentation suggests to use env:

steps:
  - name: Print github context
    env:
      GITHUB_CONTEXT: ${{ toJSON(github) }}
    run: echo "$GITHUB_CONTEXT"

docs.github.com

Context and expression syntax for GitHub Actions - GitHub Docs

An alternative in bash is to use cat with heredoc syntax and quotes around the delimiter definition to disable substitution:

steps:
  - name: Print github context
    run: |
      cat<<'EOF'
      ${{ toJSON(github) }}
      EOF

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants