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):
and last but not least, here's my code:
echo " Please enter the path to the file you want to check:"
echo " Now the SHA1 provided by the publisher:"
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!).
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: