我想计算几个CRC并比较它们,看它们是否相似。换句话说x!= y s.t. CRC(x)== CRC(y)。我到目前为止编写的代码是:
#!/bin/bash
clear;
echo "The script starts now"
$SECONDS = 0;
while(true)
do
./pycrc.py --model crc-32 --check-string $RANDOM
./pycrc.py --model crc-32 --check-string $RANDOM
done
echo "The script is finish"
echo "That took approximately $SECONDS seconds"
如何设法保存./pycrc.py
的输出并比较变量?
答案 0 :(得分:4)
使用Command Substitution捕获输出,使用Conditional Expressions进行比较。像这样:
value1="$(./pycrc.py --model crc-32 --check-string $RANDOM)"
value2="$(./pycrc.py --model crc-32 --check-string $RANDOM)"
if [[ $value1 == $value2 ]]; then
echo "Values match!"
fi