Skip to content
Latchkey

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

Terminal
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
EOF

Options

Flag / itemWhat it does
-n / --numberNumber all output lines
-A / -v / -e / -tShow non-printing chars / line ends / tabs
-s / --squeeze-blankCollapse repeated blank lines
<<EOFHere-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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →