[arch-general] broken pipe

Pascal patatetom at gmail.com
Wed Dec 18 14:20:04 UTC 2019


hello,

to avoid having to read twice the entire large file, I use the tee tool in
this way to calculate two checksums "simultaneously" :

file_info(){
    echo -n ${1:=/dev/stdin}$'\t'
    (
        tee < "${1}" \
            >( md5sum >&3 ) \
            >( sha1sum >&3 ) \
            >/dev/null
    ) 3>&1 |
    tr '\n' '\t'
    echo
}

it works perfectly because both tools used, md5sum and sha1sum, consume all
the data.

on the other hand, the function returns wrong fingerprints if I insert a
tool like file :

file_info(){
    echo -n ${1:=/dev/stdin}$'\t'
    (
        tee < "${1}" \
            >( file --mime-type -b -e compress -e tar -e elf - >&3 ) \
            >( md5sum >&3 ) \
            >( sha1sum >&3 ) \
            >/dev/null
    ) 3>&1 |
    tr '\n' '\t'
    echo
}

it no longer works because the data flow is quickly interrupted by tee
which does not consume all the data.

do you know a way to get the file type in parallel with the fingerprint ?

getting its type is just an example : the idea is to open the file only
once...

regards, lacsaP.


More information about the arch-general mailing list