Skip to content

Instantly share code, notes, and snippets.

@BCadet
Last active August 1, 2024 07:15
Show Gist options
  • Save BCadet/03ccc936d3ac5897a9c2d511bd4b1461 to your computer and use it in GitHub Desktop.
Save BCadet/03ccc936d3ac5897a9c2d511bd4b1461 to your computer and use it in GitHub Desktop.
cat magic stdin/out redirection and mixing

How to abuse cat stdin to redirect file content

cat with stdin EOF tag can be used to mix stdin input and file content

cat - << 'EOF' "file.txt"
text from stdin to prepend to file.txt content
EOF

would print to the stdout the line text from stdin to prepend to file.txt content and after the content of file.txt

optionnaly, the output of the cat command can be redirected to a file with the line cat - << 'EOF' "file.txt" > out.txt or event piped to another command with a similar line: cat - << 'EOF' "file.txt" | sed ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment