i need to store the outputs of 2 commands in 2 variables and compare the two variable
i need to compare the output from the md5sum of 2 files
when i run this script i get the output is wrong 1 yes 2 yes 3 yes 4 yes 5 yes here is the script g=`tail -1 new.txt|head -n 1`# for reading a value from new.txt for (( i=1; i<$g+1; i++ )) do echo $i a=`md5sum data$i` b=`md5sum dat` if [ "$a"=="$b" ] then echo yes else echo no fi done actually only data1 is same as dat but the rest are different but i get yes for values of i. can anyone please help me? |
Not sure if it is the only problem with your script, but you should use "=" not "==" in your if test.
Evo2. |
i changed the "==" to "=" and still i get the same output
|
You should echo the values of $a and $b in the script so that you can see what they are.
Evo2. |
1
6b465c608623058c4ccf24149012dfa3 data1 6b465c608623058c4ccf24149012dfa3 dat yes 2 2559d5fd84bfadaf77bb63fd0459e23a data2 6b465c608623058c4ccf24149012dfa3 dat yes 3 5f977efefe9e832a30b2ca874a552386 data3 6b465c608623058c4ccf24149012dfa3 dat yes 4 5f977efefe9e832a30b2ca874a552386 data4 6b465c608623058c4ccf24149012dfa3 dat yes 5 c173ba16e9f6b482653760b675f57a01 data5 6b465c608623058c4ccf24149012dfa3 dat yes this is the output i get |
Actually even the first one should not match since a ends in "data1" and b ends in "dat". Anyway the problem seems to be that you did not leave a space either side of the "=" in the if statement.
Evo2. |
Is your script running as a bash script or as something else? You can ensure that it is run as a bash script by using this first line
Code:
#!/bin/bash Code:
[ "$a" == "$b" ] It's easier to read your code if you put it in code tags (that's a link to instructions or you may prefer to use "Advanced Edit" mode which has a # button for code tags). |
oh ok .. you're right.. when i added the space .. i got all of them as no.. is there anyway of preventing md5sum from printing the filename?
|
You can just cut out the field you want.
Code:
a=`md5sum data$i | cut -f1 -d' '` Evo2. |
it works ! thanx
|
Quote:
|
All times are GMT -5. The time now is 04:44 AM. |