bash save to file code example

Example 1: echo to file bash

echo "I am \"Finding\" difficult to write this to file" > file.txt
echo "I can \"write\" without double quotes" >> file.txt

echo "This is a test to write $PATH in my file" >> file.txt
echo 'This is a test to write '"$PATH"' in my file' >> file.txt

tee -a file.txt <<EOF

I am "Finding" difficult to write this to file
I can "write" without double quotes
EOF

Example 2: bash write file

# syntax (note: the -e switch is to allow for backslash escapes)
# echo -e "<string-to-append>" >> <file-to-append-to>

# example 
echo -e "Hello there, new line!" >> RandomWorld.txt

# -----------------------------------------------
# In order to see the effect of -e, use the following string:
# "Hello there,\n new line!"

Example 3: pipe commands into a text file bash

command > file.txt