4

I have stored a multiline environnement variable thanks to github docs.

- name: copy
  run: |
     echo 'CONTENT_ENV<<EOF' >> $GITHUB_ENV
     cat README.md >> $GITHUB_ENV
     echo 'EOF' >> $GITHUB_ENV

I would like to get it, but this code give one line :

 - name: paste
   run: echo $CONTENT_ENV > index.md

The worflow shows the variable properly stored in env (with spaces) :

workflow

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
Foxhunt
  • 764
  • 1
  • 9
  • 23
  • Does this answer your question? [How to store and echo multiple lines elegantly in bash?](https://stackoverflow.com/questions/2752654/how-to-store-and-echo-multiple-lines-elegantly-in-bash) – Chris Stryczynski Jan 13 '23 at 10:15

1 Answers1

5

Your variable is properly stored, but you need to add quotes if you want to preserve the newlines :

- name: paste
  run: echo "$CONTENT_ENV" > index.md
- name: test
  run: cat index.md

Short explanation is that default field separator is whitespace (space, tab and newline), so if you don't use quotes, echo will consider all newlines separated strings as different arguments. See this post for more in-depth explanation

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159