Use BASH here documents whenever you need a multi-line text inside redirection.

Create or replace a file with a multi-line content.

$ tee /tmp/file << DELIMITER_KEYWORD
line 1
line 2
line 3
DELIMITER_KEYWORD
line 1
line 2
line 3

Append a multi-line content to a file

$ tee --append /tmp/file << EOT
line 4
line 5
EOT
line 4
line 5

Inspect created file.

$ cat /tmp/file 
line 1
line 2
line 3
line 4
line 5

Use sudo whenever you need to gain elevated privileges.

$ sudo tee /tmp/hosts << EOTEE
172.16.254.254    desktop
EOTEE
172.16.254.254    desktop

Variable expansion and command substitution is performed by default.

$ tee /tmp/varaible_values << EOF
$USER $SHELL $(echo $HOME) \$HOME
EOF
milosz /bin/bash /home/milosz $HOME

Quote the delimiter keyword to prevent variable expansion and command substitution.

$ tee /tmp/varaible_names << 'EOF'
$USER $SHELL $(echo $HOME) \$HOME
EOF
$USER $SHELL $(echo $HOME) \$HOME

Using here documents can look out of place inside shell scripts, so you can use <<- redirection operator to strip leading tab characters.

if test -v HOME; then
	tee /tmp/home <<- EOF
		$HOME
	EOF
fi
$ cat /tmp/home 
/home/milosz

This is a very basic knowledge, but still worth a reading. There are things like cat overuse or similar habits that I am still trying to get rid of. The best thing I can do is to write it down and stick to it.

ko-fi