Reputation: 624
I am trying to use the GitHub action create-file
As part of my GitHub workflow I would like to create a text file like:
version=<version number>
released=<date>
where <version number>
and <date>
are variables previously defined in my script.
Hence, I tried the following:
FILE_DATA: "version=${{steps.read_version.outputs.value}}\nreleased=${{env.TODAY}}"
but \n
is interpreted as space and not as a break line hence generated a single line file.
Looking at the source code of the GitHub action, it seems it only execute
echo $FILE_DATA > "$FILE_NAME"
Where $FILE_NAME"
is equals in my case to ./docs/version.properties
Hence I tried to do what I wanted directly by using echo
command instead of the GitHub action but whatever I tried it failed to properly render the \n
.
Any suggestion would be very welcome.
Upvotes: 1
Views: 2566
Reputation: 154
it seems to be a syntax issue.
- name: Write multiline text to file
shell: bash
run: |
{
echo '$FILE_DATA'
} >> $FILE_NAME
I had the same issue in my workflow file. In this workflow file I also write multiple lines of text into a file.
Edit:
Sorry, I misunderstood your question.
Simply use echo -e
and double quotes... .
#!/bin/bash
version="1.1"
released="01-10-2022"
myString1="version=$version\nreleased=$released"
echo -e "$myString1" > test1.txt
Output:
version=1.1
released=01-10-2022
Upvotes: 2