Skip to content

Instantly share code, notes, and snippets.

@d630
Created June 22, 2016 21:14
Show Gist options
  • Save d630/46c00265785864d91b7cabf30604d983 to your computer and use it in GitHub Desktop.
Save d630/46c00265785864d91b7cabf30604d983 to your computer and use it in GitHub Desktop.
bash: read stdin from pipe into variable
% printf '%d\n' {1..10000} | { time a=$(</dev/stdin) ; echo "$a"; } | wc -c
real 0m0.027s
user 0m0.004s
sys 0m0.004s
48894
% printf '%d\n' {1..10000} | { time read -rd '' a; echo "$a"; } | wc -c
real 0m0.041s
user 0m0.004s
sys 0m0.016s
48894
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment