Concatenate FILE(s) to stdout in pure BASH as an executable or sourceable script.
cat.bash [FILE]...
With no FILE, or when FILE is -, read standard input.
# Optional: source cat.bash to define cat.bash as a function for better performance.
source cat.bash
cat.bash '/path/to/file1' '/path/to/file2' > combined.txt
printf 'b' | cat.bash <(printf 'a') - <(printf 'c')
# stdout: abc
cat.bash < file-to-copy > copy-of-file
cat.bash <<-'EOF' > message.txt
Hello from a heredoc
EOF
Copying a binary:
cat.bash "$(which bash)" > /tmp/bash_copy
md5sum "$(which bash)" /tmp/bash_copy
# stdout:
# e979d93c05b74fb89fd21eb312f81d3d /usr/bin/bash
# e979d93c05b74fb89fd21eb312f81d3d /tmp/bash_copy
Copying null characters:
printf '\0\0\0null\0\0\0characters\0\0\0' | cat.bash | sed 's/\o0/\\0/g'
# stdout: \0\0\0null\0\0\0characters\0\0\0
Licensed under Creative Commons, CC0 1.0 Universal. See LICENSE for details.