Cat
lastmod 2026-02-06created 2015-10-2014 edits
The cat command can print the contents of a text file, or concatenate two or more files and print them.
Example
Print with a number on each line:
Number blank lines too:
Print two or more consecutive blank lines as a single line:
Assign multi-line string
Examples of cat <<EOF syntax usage in Bash. For reference, this technique is called a Here document. See that page for details.
Assign multi-line string to a shell variable
The $sql variable now holds the new-line characters too. You can verify with echo -e "$sql"
Pass multi-line string to a file in Bash
The print.sh file now contains:
Pass multi-line string to a pipe in Bash
The b.txt file contains bar and baz lines. The same output is printed to stdout.
To prevent environment variable substitution
Used as follows, $temp is substituted as an environment variable.
To prevent this, quote EOF with single quotes ('EOF').
Text Processing Commands
|