cat: Usage, Options & Common CI Errors
cat prints files to stdout and is the usual front-end for here-documents in scripts.
cat is simplest of all, but in CI it is the standard way to write multi-line files via here-docs - and quoting the heredoc delimiter decides whether variables get expanded.
What it does
cat reads files (or stdin) and writes their contents to stdout, in order. In scripts it is most often used with here-documents to generate config files inline.
Common usage
cat file.txt
cat a.txt b.txt > combined.txt
cat -n file.txt # number lines
cat <<EOF > config.env # heredoc: $VARS expand
HOST=${HOST}
EOF
cat <<'EOF' > literal.txt # quoted EOF: no expansion
$KEEP_ME_LITERAL
EOFOptions
| Flag / item | What it does |
|---|---|
| -n / --number | Number all output lines |
| -A / -v / -e / -t | Show non-printing chars / line ends / tabs |
| -s / --squeeze-blank | Collapse repeated blank lines |
| <<EOF | Here-doc; variables and command subst expand |
| <<'EOF' | Quoted here-doc; content is literal |
Common errors in CI
cat: file.txt: No such file or directory exits 1 - the path is wrong or a prior step did not produce it. With here-docs, an unquoted <<EOF expands $VAR and cmd (good for templating, dangerous for literal $ in passwords) while quoted <<'EOF' keeps everything literal. A heredoc whose closing EOF is indented will not terminate unless you use <<-EOF and indent only with tabs. Avoid "useless cat" (cat f | grep x); prefer grep x f.