What is a here-document, and what is the difference between `<<EOF`, `<<'EOF'` and `<<-EOF`?
BeginnerConceptArguments, I/O, here-docs, process substitution and subshells
Answer
A here-doc feeds the following lines to a command's stdin until the delimiter line.
cat > /etc/app/app.env <<EOF # unquoted: $vars and $(cmds) expand
APP_ENV=$env
BUILD=$(git rev-parse --short HEAD)
EOF
cat > deploy-remote.sh <<'EOF' # quoted: literal, nothing expands
echo "running on $(hostname) as $USER"
EOF
if true; then
cat <<-EOF # <<- strips leading TABS (not spaces)
indented with tabs
EOF
fi
The closing delimiter must be alone on its line with no trailing spaces. Use <<'EOF' when generating scripts or configs containing $ that must survive.
More on Arguments, I/O, here-docs, process substitution and subshells
How does `getopts` work? Show a complete example.IntermediateWhat is the difference between `getopts` and `getopt`?AdvancedExplain file descriptors 0, 1 and 2 and the main redirection operators.BeginnerWhy is `cmd 2>&1 > file` different from `cmd > file 2>&1`?AdvancedWhat is a here-string (`<<<`)?IntermediateHow do you send a here-doc to a remote server over SSH, and when should variables expand locally vs remotely?Advanced