我有一个bash脚本:
#!/bin/bash
pathToTestCasesFile=$1
while IFS=';' read -r col1 col2
do
if [[ $col1 == V[0-9]:* ]]; then
echo "decrypt"
if [[ "$(decrypt "$col1")" == "$col2" ]] ; then
echo "$col1 is equal to $col2"
else
echo "$col1 is not equal to $col2"
fi
else
echo "encrypt"
if [[ "$(encrypt $col1)" == "$col2" ]] ; then
echo "$col1 is equal to $col2"
else
echo "$col1 is not equal to $col2"
fi
fi
done < $pathToTestCasesFile
exit 0
这是测试文件:
alex;V1:IVjd9qcAbUrR954gyPDbKw==
V1:IVjd9qcAbUrR954gyPDbKw==;alex
输出如下:
encrypt
alex is not equal to V1:IVjd9qcAbUrR954gyPDbKw==
decrypt
V1:IVjd9qcAbUrR954gyPDbKw== is not equal to alex
decrypt
但输出应该说一切都是平等的。
我确信在命令de -encrypt之后,该值等于另一个。我单独测试了它。
比较可能存在问题..
非常感谢你的帮助。
答案 0 :(得分:1)
这应该有效:
#!/bin/bash
while IFS=, read -r col1 col2
do
echo "I got|$col1|$col2|"
if [[ "$col1" =~ V.:.* ]]; then
echo "decrypt"
if [[ "$(decrypt "$col1")" == "$col2" ]] ; then
echo "[$col1] is equal to [$col2]"
else
echo "[$col1] is not equal to [$col2]"
fi
else
echo "encrypt"
if [[ "$(encrypt "$col1")" == "$col2" ]] ; then
echo "[$col1] is equal to [$col2]"
else
echo "[$col1] is not equal to [$col2]"
fi
fi
done < "$pathToTestCasesFile"
对于字段分隔符,使用,
逗号 - 与代码中一样。在示例数据中,您有;
。如果您需要;
,请将IFS=,
更改为IFS=';'
。