Shell Script (Bash) write to Text-File question

I have a question I could not find an answer to (certainly due to my lack of knowledge of shell syntax).
I have an automator program that adds a new line to a textfile with a shell command:

 echo -e "$@\n$(cat "/Users/(...)/Documents/Text-File.txt")" > "/Users/(...)/Text-File.txt"

My problem is, that it adds the new line on top of the text file, but I need it at the end or somewhere within the document (that does not matter – just not on top, because there is a needed headline…). Does someone know how I could change the shell to do that?

The > operator should be overwriting your file every time. If you want to append to the file, you should use >>.

1 Like

Thank you for your fast reply!
If I put that into the script, the whole text is doubled and added to the file… can I avoid that?

I think that’ll be because you are cating your file as well as the new line.

Just echo the new line and append redirect (>>) that to your file.

See also:

1 Like

That works perfectly! Thank you and thanks for the Link – its very helpful!