I'm trying to make a quick & dirty bash function to compare the audio content of two FLAC files without decoding them into a temp file. With the flac command line tool I'm decoding each file into a named pipe and then comparing them with cmp:

function flacdiff {
        local pipe1="/tmp/$(randomString)"
        mkfifo "$pipe1" 
        flac --silent --decode --force-raw-format --sign=signed --endian=little "$1" --stdout > "$pipe1" &

        local pipe2="/tmp/$(randomString)"
        mkfifo "$pipe2"
        flac --silent --decode --force-raw-format --sign=signed --endian=little "$2" --stdout > "$pipe2" &

        cmp -b "$pipe1" "$pipe2"
        local result=$?

        rm "$pipe1"
        rm "$pipe2"

        return $result

If the files are identical, the script works correctly. However if they're different I get a broken pipe error:

[1]-  Broken pipe: 13         flac --silent --decode --force-raw-format --sign=signed --endian=little "$1" --stdout > "$pipe1"
[2]+  Broken pipe: 13         flac --silent --decode --force-raw-format --sign=signed --endian=little "$2" --stdout > "$pipe2"

I assume that this is because cmp stops reading as soon as it encounters the first mismatch while the write end of the pipes is still active. My question is whether this hypothesis is true, and whether if it's possible to avoid these broken pipe errors and fix my script?

  • yes. you can handle it with trap ' do stuff ' PIPE if you want.
    – mikeserv
    Jan 13, 2016 at 19:17

1 Answer 1



cmp -s \
    <(flac --silent --decode --force-raw-format --sign=signed --endian=little "$1" --stdout) \
    <(flac --silent --decode --force-raw-format --sign=signed --endian=little "$2" --stdout)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .