I am using
sha256sum to check whether file has changed or not within the bash script. My idea is to first store the
sha256sum in a
*.sha256 file. Then if this is present then use this for
sha256 comparison using
--check command. If hashes match then continue the rest of script otherwise create new hash file (
*.sha256) and replace the older one with new hash file. I have done:
x="/home/test.json" if [[ -s $x.sha256 ]]; then sha256sum --check $x.sha256 #exit 1 s1=$(sha256sum "$x" > "$x.sha256") #exit 1 else s1=$(sha256sum "$x" > "$x.sha256") echo "sha256 file is created" fi
But from above code initially if x.sha256 file is not present, then it is created. But if file is already available and hashes doesn't match then it throws error:
/home/test.json: FAILED sha256sum: WARNING: 1 computed checksum did NOT match
This is expected but in this case I want to create new
x.sha256 file and replace old file.
Can anyone please let me know what changes is needed?
Thanks in advance