How to cat a file containing code?

You only need a minimal change; single-quote the here-document delimiter after <<. cat <<‘EOF’ >> brightup.sh or equivalently backslash-escape it: cat <<\EOF >>brightup.sh Without quoting, the here document will undergo variable substitution, backticks will be evaluated, etc, like you discovered. If you need to expand some, but not all, values, you need to individually escape … Read more

How does “cat

The cat <<EOF syntax is very useful when working with multi-line text in Bash, eg. when assigning multi-line string to a shell variable, file or a pipe. Examples of cat <<EOF syntax usage in Bash: 1. Assign multi-line string to a shell variable $ sql=$(cat <<EOF SELECT foo, bar FROM db WHERE foo=’baz’ EOF ) … Read more

How can I write a heredoc to a file in Bash script?

Read the Advanced Bash-Scripting Guide Chapter 19. Here Documents. Here’s an example which will write the contents to a file at /tmp/yourfilehere cat << EOF > /tmp/yourfilehere These contents will be written to the file. This line is indented. EOF Note that the final ‘EOF’ (The LimitString) should not have any whitespace in front of … Read more