[Bash] Write multiple lines to a file with a here document

Created on November 30, 2026

You can pass multiple lines to cat with a Bash here document and redirect its output to a file. This example writes JSON to taro.json.

cat <<'JSON' > taro.json
{
  "name": "Taro",
  "age": 20
}
JSON

<<'JSON' supplies the lines up to the closing JSON marker. Quoting the opening delimiter keeps the contents literal. > taro.json creates the file or replaces its contents if it already exists.

Bash