1

我想计算几个CRC并比较它们以查看它们是否相似。换句话说,x != y st 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并比较变量?

4

1 回答 1

4

使用命令替换来捕获输出和条件表达式以进行比较。像这样:

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
于 2012-09-29T03:26:01.303 回答