Script to check if two variables match always says they match even if they don't bash
I am trying to write a script that has two variables one named sha that has the value that I want to check if the variable hi is equal to that value. the variable hi is suppossed to be the result of sha1sum gnupg-1.4.19.tar.bz2 but no matter if the file has the correct sha1 checksum or not it still displays: The sha1sum checksums match. What am I doing wrong?
Code:
sha="5503f7faa0a0e84450838706a67621546241ca50 gnupg-1.4.19.tar.bz2" |
You need spaces between the variables and the test in your if-statement
Code:
if [ "$hi" == "5503f7faa0a0e84450838706a67621546241ca50 gnupg-1.4.19.tar.bz2" ] |
Your issue is the lack of spacing around the test (==)
|
Different problem
I added the spaces and now it always says that they don't match (outputs failed every time.):
Thanks for helping! Code:
sha="5503f7faa0a0e84450838706a67621546241ca50 gnupg-1.4.19.tar.bz2" |
Hi,
I think this might be a whitespace issue. Is there really just one space between the checksum and the filename in the output? Alternatively, this is not a direct answer to your question, but a suggestion of a "better" way to do this. You can use the -c option. Eg Code:
echo "5503f7faa0a0e84450838706a67621546241ca50 gnupg-1.4.19.tar.bz2" > files.txt |
Solved but still question.
Thank you evo2 for solving my issue, there is two spaces in the output. Is the way of doing it with the -c option still a better way of doing it?
|
Hi,
Quote:
Quote:
Cheers, Evo2. |
Solved but an invitation.
To all of the people that helped me: Thanks a lot! And will you audit my script? (big changes coming soon.) https://github.com/mathwhiz1212/auto...pg/tree/master
|
I agree the file checksum process is probably better, but thought I would present an alternative:
Code:
#!/usr/bin/env bash |
What would that look like?
Sorry for awakening the thread but @evo2 can you show me how I would modify my if then statement to use:
Code:
echo "5503f7faa0a0e84450838706a67621546241ca50 gnupg-1.4.19.tar.bz2" > files.txt |
I think I've got it.
I think I've got it:
Code:
echo 5503f7faa0a0e84450838706a67621546241ca50 gnupg-1.4.19.tar.bz2 > gpg.sha |
Hi,
it's probably better to use the exit status instead. It will be 0 for a match 1 for fail. Eg Code:
sha1sum --status -c gpg.sha |
All times are GMT -5. The time now is 06:04 PM. |