Hacker News new | past | comments | ask | show | jobs | submit login

Maybe this thread is the right place to ask a usage question: I have a multiline GitHub Secret which I would like to print out to a `.env` file in a GitHub Action. How can I do that?

My current solution doesn't support spaces within the secret content:

  - name: Write .env
    run: |
      echo $ENV_FILE | tr ' ' '\n' > .env
    shell: bash
    env:
      ENV_FILE: ${{secrets.DOTENV}}

Writing a multiline secret string directly into a file replaces all newlines with spaces. The `tr` command converts them back to newlines.



`echo "$ENV_FILE"`, maybe? `echo $ENV_FILE` (without quotes) will split the environment variable by separators in $IFS and pass each chunk as separate argument.


You have to quote your variable expansion.

Also using echo is bad form, instead try

   cat <<<$ENV_FILE >.env




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: