How can I write data to a text file automatically by shell scripting in Linux?
I was able to open the file. However, I don't know how to write data to it.
The short answer:
echo "some data for the file" >> fileName
However, echo doesn't deal with end of line characters (EOFs) in an ideal way. So, if you're gonna append more than one line, do it with printf:
echo
printf
printf "some data for the file And a new line" >> fileName
The >> and > operators are very useful for redirecting output of commands, they work with multiple other bash commands.
>>
>
1.4m articles
1.4m replys
5 comments
57.0k users