OS X (Apple)

OS X is a line of Unix-based graphical operating systems developed, marketed, and sold by Apple.

SHA1 verification script

👤 Login to reply

Old 02-15-2017
Ardzii Ardzii is offline
Registered User
Apple SHA1 verification script

Hi guys!

Me again! ...
I'm trying to build (on MacOS directly) a bash script that will help me verify a SHA1 digest (to verify downloads and so on and so forth).

So first off, here's my version of BASH under OSX:

And here's my version of Sierra (macOS):
10.12.3 (16D32)

and last but not least, here's my code:


declare sha1=""
declare PATH=""
declare verifySha=""

echo " Please enter the path to the file you want to check:"
read PATH
echo " Now the SHA1 provided by the publisher:"
read sha1
verifySha=$(openssl sha1 $PATH)
if [ $sha1 -eq $verifySha ]
        echo "OK, same here!"
        echo "Not the same, try again!"

Now, I know that $sha1 and $verifySha will not be the same for now... I need a sed in the middle to extract the sha signature.
But, aside from this minor problem that I will fix soon, I get the error:
./shaVerif.sh: line 17: openssl: command not found
./shaVerif.sh: line 18: [: 7798b65ae8842768bd2ff068545e0a3fc2dd0140: unary operator expected

Anyone has any idea why the openssl command does not work in a bash script? (Obviously, when I try to pass the command outside of the script, it works!).
Sponsored Links
Old 02-15-2017
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
  1. declare PATH="" GULP, this removes all the paths to any executables.
  2. [ $sha1 -eq $verifySha ] should read [ "$sha1" = "$verifySha" ] .
This is just a starter, I have not checked your logic, but this should help you out at least...

Last edited by rbatte1; 02-15-2017 at 09:36 AM.. Reason: Converted textual list to formatted numbered list and corrected spellings
Sponsored Links
Old 02-15-2017
RudiC RudiC is offline Forum Staff  
As wisecracker said, openssl is not found because you removed the PATH info that bash uses to find commands. Use a different file name or - less recommendable - the absolute path to openssl.
With bash 4.4 you should be able to use "here strings"; no need to use sed or other. Try:
read dummy verifySha <<< $(openssl sha1 $FILEPATH)

Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Field verification script help galford Shell Programming and Scripting 2 10-31-2013 03:32 PM
Verification on shell script nimafire Shell Programming and Scripting 8 09-23-2013 08:29 AM
Script Verification k33k00 Shell Programming and Scripting 1 04-07-2012 07:32 AM
Email address verification script Ramdas Shell Programming and Scripting 4 01-15-2007 01:51 AM
Verification of a script already running - where to do it miwinter UNIX for Dummies Questions & Answers 2 08-07-2006 10:32 AM

All times are GMT -4. The time now is 09:39 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
Show Password

Not a Forum Member?
Forgot Password?