How to compute double sha256 shown in examples of bip 143?
Do this:

echo -n $PREV_OUT | xxd -r -p | openssl dgst -sha256 -binary | openssl dgst -sha256


Explanation

You want to do this:


  prevout (raw bytes) -> sha256 -> sha256 -> convert to hex


You're doing this:


  prevout (raw bytes) -> convert to hex -> sha256 -> sha256 -> convert to hex


xxd -r -p reverses the hex conversion.