0

I have a hash file that contains only the digest:

cat archive.hash
DBD47245A6E78626CBAD9A228C8956741BBA853E9D4A1DFCA6E335366C438C26341321E83B614834F78CD4D8FF71B05D5ADE8FAB3E0ECE5EF34A486D09882BB7

In order to accept the hash file as input and check, the sha512sum command requires that the file is formatted with a low chars digest followed by two spaces and the file name:

9a228c8956741bba853e9d4a1dfca6e335366c438c26341321e83b614834f78cd4d8ff71b05d5ade8fab3e0ece5ef34a486d09882bb7  archive.zip

I tried several syntax such as:

 sha512sum -c <(echo "$(cat archive.hash |tr A-Z a-z) archive.zip")

But I receive this error:

sha512sum: /dev/fd/63: no properly formatted SHA512 checksum lines found

Analyzing the string:

echo "$(cat archive.hash |tr A-Z a-z) archive.zip"

The output is this:

archive.zip9a228c8956741bba853e9d4a1dfca6e335366c438c26341321e83b614834f78cd4d8ff71b05d5ade8fab3e0ece5ef34a486d09882bb7

It put the file name in front of the hash digest. How can this problem be avoided?

bonzix
  • 45
  • 5
  • 2
    **Your file has a CRLF line ending** perhaps because it came from or was editted on Windows. Look at it with `cat -vE` or `od -c` or `sed -n l` (that's ell not one) to see/confirm. Remove the CR with `dos2unix` or `tr -d '\r'` or `sed 's/\r$//'`. Note you don't put 2 spaces, but the `shasum` format doesn't actually require 2 spaces just 1. – dave_thompson_085 Feb 03 '23 at 12:10
  • 1
    `How can this problem be avoided?` Your file has dos line endings. Remove them. It can be avoided by not adding them. – KamilCuk Feb 03 '23 at 12:11
  • 1
    See the "Before asking about problematic code" section of the [Stack Overflow 'bash' Info page](https://stackoverflow.com/tags/bash/info). – pjh Feb 03 '23 at 12:27
  • 1
    Also see [Are shell scripts sensitive to encoding and line endings?](https://stackoverflow.com/q/39527571/4154375) and [How to convert Windows end of line in Unix end of line (CR/LF to LF)](https://stackoverflow.com/q/3891076/4154375). – pjh Feb 03 '23 at 12:28
  • I didn't know it was a file generated by a Windows system. I managed to solve the problem with this syntax: `sha512sum -c <(echo "$(cat archive.hash |dos2unix|tr A-Z a-z) archive.zip")` – bonzix Feb 03 '23 at 14:32

0 Answers0