我正在嘗試將復制檔案的哈希值與 bash 進行比較,但條件不起作用。
└──? $bash check-256.sh cal.sh 2cal.sh
ea8f4b5acdeb26015661ee27c9000af97691a0fd715be94b2b3eda6a3d02c789 cal.sh
ea8f4b5acdeb26015661ee27c9000af97691a0fd715be94b2b3eda6a3d02c789 2cal.sh
#!/bin/bash
First_file=$(sha256sum $1)
Second_file=$(sha256sum $2)
echo "$First_file"
echo "$Second_file"
[ "$First_file" == "$Second_file" ] && echo "Pass" || echo "Fail"
uj5u.com熱心網友回復:
條件失敗,因為結果字串實際上并不相同。您需要使用 cut 命令洗掉散列。
#!/bin/bash
First_file=$(sha256sum $1 | cut -d' ' -f1)
Second_file=$(sha256sum $2 | cut -d' ' -f1)
echo "$First_file"
echo "$Second_file"
[ "$First_file" == "$Second_file" ] && echo "Pass" || echo "Fail"
cut -d' ' -f1
- -d 指定分隔符。在這種情況下,我們使用單個空格
- -f1 選擇輸出的欄位。在這里,我們只想擁有第一個欄位,即哈希
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/491927.html
