2013-10-13 65 views
2

我在AWK運行的md5sum找到同一個文件:運行的md5sum命令

ls -lS | awk 'BEGIN { 
    getline;getline; 
    name1=$9;size1=$5 
} 
{ 
    name2=$9;size2=$5; 
    if (size1==size2) { 
     cmd1="md5sum "name1 
     cmd2="md5sum "name2 
     cmd1 | getline; sum1=$1 
     cmd2 | getline; sum2=$1 
     print sum1,sum2 
     if (sum1 == sum2) { 
      print name1;print name2 
     } 
    }; 
    name1=name2;size1=size2 
}' 
  1. 我的外殼的輸出是:

b1946ac92492d2347c6235b4d2611184 b1946ac92492d2347c6235b4d2611184
測試
test_cpy1
-rw-rw-r-- b1946ac92492d2347c6235b4d2611184

你可以看到有一個的md5sum是不正確的......但如果我改變兩個CMD行順序:

cmd2 | getline; sum2=$1 
cmd1 | getline; sum1=$1 

輸出是正確的。我很困惑...

b1946ac92492d2347c6235b4d2611184 b1946ac92492d2347c6235b4d2611184 
test 
test_cpy1 
b1946ac92492d2347c6235b4d2611184 b1946ac92492d2347c6235b4d2611184 
test_cpy1 
test_cpy2 

回答