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

What does set -e mean in a bash script?

From help set : -e Exit immediately if a command exits with a non-zero status. But it’s considered bad practice by some (bash FAQ and irc freenode #bash FAQ authors). It’s recommended to use: trap ‘do_something’ ERR to run do_something function when errors occur. See http://mywiki.wooledge.org/BashFAQ/105

Reading quoted/escaped arguments correctly from a string

A Few Introductory Words If at all possible, don’t use shell-quoted strings as an input format. It’s hard to parse consistently: Different shells have different extensions, and different non-shell implementations implement different subsets (see the deltas between shlex and xargs below). It’s hard to programmatically generate. ksh and bash have printf ‘%q’, which will generate … Read more

What is the difference between $(command) and `command` in shell programming?

The backticks/gravemarks have been deprecated in favor of $() for command substitution because $() can easily nest within itself as in $(echo foo$(echo bar)). There are other differences such as how backslashes are parsed in the backtick/gravemark version, etc. See BashFAQ/082 for several reasons to always prefer the $(…) syntax. Also see the POSIX spec … Read more