mathiasbynens/dotfiles — comment on commit 9b0af44766d2a2cc61ae0142ac3ec9f0bed75674
File:  line 0
By janmoesen:

First, you should use `read -r` to prevent unwanted unescaping:

-----[ 14:43:07 ] (!8180) [ :-) ] janmoesen@janmoesen ~
$ read <<< 'foo\nbar'; echo "$REPLY"
foonbar
-----[ 14:43:30 ] (!8181) [ :-) ] janmoesen@janmoesen ~
$ read -r <<< 'foo\nbar'; echo "$REPLY"
foo\nbar

(I am guilty of using `read` instead of `read -r` quite often, myself. Don't take this as me being holier than thou.)

Apart from that, I don't think this snippet does what you think it should do. Now you spawn the Python tool for every line of input, as opposed to once for all lines combined. Get rid of the whole `while` loop, and simply let the `python` process handle the input:

if [ -p /dev/stdin ]; then
python -mjson.tool | pyg…