Skip to content

Instantly share code, notes, and snippets.

@bkw777
Last active May 19, 2026 15:20
Show Gist options
  • Select an option

  • Save bkw777/92ed6327873ef96088475bedc44e2ba5 to your computer and use it in GitHub Desktop.

Select an option

Save bkw777/92ed6327873ef96088475bedc44e2ba5 to your computer and use it in GitHub Desktop.
cat without cat
# minimal example just for reference, not pointful by itself
# binary-safe read/write file without cp/cat/dd etc, pure bash, no subshell
while LANG=C IFS= read -d '' -r -n 1 x ;do printf '%c' "$x" ;done <bin1 >bin2
# slightly useful example, count bytes to get filesize without stat/ls/wc etc
n=0 ;while LANG=C IFS= read -d '' -r -n 1 ;do ((n++)) ;done <bin # filesize = $n bytes
@bkw777
Copy link
Copy Markdown
Author

bkw777 commented Jul 23, 2025

from a comment on another gist, slightly different version that reads non-nulls contiguously instead of every single byte individually
https://gist.github.com/bkw777/ddde771cc85fdd888c7ec74953193d66?permalink_comment_id=5686772#gistcomment-5686772

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