The echo command is the easiest way to append a new line to the end of a file. In this example, "Hello World" will be appended to the end of example.txt.
echo "Hello World" >> example.txt
The sed command with the a (append) flag can be used to append lines to a file or variable. For example, let's say you have a file or variable with the following text.
The following command will add "New Text" to the file or variable. The a flag in this command is used to append.
sed -i '/Hello World/a New Text' $foo
In this example, the file or variable will have the following output.
Hello World New Text