SHA1 verification script

Login or Register to Reply

Thread Tools Search this Thread
# 1  
Old 02-15-2017
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:
./ line 17: openssl: command not found
./ 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!).
# 2  
Old 02-15-2017
  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
# 3  
Old 02-15-2017
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)

Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
ECDSA verification dragonpoint Programming 0 05-24-2016 08:56 PM
Help about comment verification learnbash Shell Programming and Scripting 5 01-28-2014 04:42 AM
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
sha1 question locoroco Shell Programming and Scripting 12 03-07-2011 12:07 AM
Script for verification of Data corruption manish_tcs_hp Shell Programming and Scripting 4 12-07-2010 08:14 PM
SHA1 hash calculation ahsaas42 Programming 4 07-03-2010 02:35 PM
HACMP verification mmersoylu AIX 1 04-22-2010 11:44 AM
parse csv file, sha1 hash and output FreddyG Shell Programming and Scripting 11 01-28-2009 12:17 PM
htable + verification kamel.seg Programming 0 06-17-2008 06:02 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
verification? sheranjem UNIX for Dummies Questions & Answers 3 06-06-2005 01:08 PM
ftp file verification gopat Shell Programming and Scripting 7 10-10-2003 11:24 AM