test abc bcd
所以我有一个名为“password”的文件,我试图逐个获取值来进行一些测试。
#!/bin/bash
for i in '1..5'
do
guess=`awk '{print $i}' password`
try=$(echo "$guess" | sha256sum)
testing="f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2"
if [" $try "==" $testing "]
then
echo "the password is $guess"
else
echo "password not found"
fi
done
所以我想用这个for循环来获取值,但是我得到for循环的错误,我不知道如何解决它。
答案 0 :(得分:1)
你在脚本中犯了错误,bash默认是基于空格分开的,bash中的字符串比较与其他编程语言不同。
参考:http://www.tldp.org/LDP/abs/html/comparison-ops.html
此代码可以解决您的问题。
#!/bin/bash
for guess in `cat password`;
do
try=$(echo "$guess" | sha256sum|awk '{print $1}')
testing="f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2"
if [ "$try" = "$testing" ]
then
echo "the password is $guess"
else
echo "password not found"
fi
done