Bash scripting question...

Associate
Joined
29 Mar 2010
Posts
831
Having a little problem with a script... I am trying to send blocks read by dd to shasum, but I want to be able to read the output status of dd before sending the output of shasum to stdout.

I started with:
dd if=./random.dat of=/dev/stdout bs=1024 count=1 skip=$i conv=notrunc 2>/dev/null | shasum -a 1; echo $?

but I am pretty sure that $? is the output status of shasum.

When I changed to:

block=`dd if=./random.dat of=/dev/stdout bs=1024 count=1 skip=$i conv=notrunc 2>/dev/null`
if [ $? -eq 0 ] ; then
echo $block | shasum -a 1
else
echo "Error in block $i"
fi

shasum was returning different values (due to some editing done by echo?).

Anyone have any suggestions?
 
echo does append a newline to the input which changes the hash.

Give it a try with 'echo -n' to remove the newline. i.e "echo -n $block | shasum -a 1"
 
Back
Top Bottom