但是我按照你的建议修改后,还是无法输出data。for ((addr=$start_addr; addr<$end_addr; addr=addr+4)); #for ((i=start_addr;i<=end_addr;i+=4)); do data=$(dd if=/dev/mem bs=4 count=1 skip=$(($addr/4)) 2>/dev/null | hexdump -e '/4 "%08x\n"') echo -n "\x55\xAA\x55\xAA" | dd of=/dev/mem bs=4 count=1 seek=$(($addr)) conv=notrunc 2>/dev/null # percent=$(echo "scale=2; ($addr - $start_addr) * 100 / ($end_addr - $start_addr)" | bc) # echo -ne "Writing: $percent%\r" done for ((addr=$start_addr; addr<$end_addr; addr+=4)); #for ((i=start_addr;i<=end_addr;i+=4)); do data=$(dd if=/dev/mem bs=4 count=1 skip=$(($addr/4)) 2>/dev/null | hexdump -e '/4 "%08x\n"') if [ "$data" == "$data_read" ]; then match_count=$((match_count+1)) fi count=$((count+1)) # percent=$(echo "scale=2; $count * 100 / (($end_addr - $start_addr) / 4)" | bc) # echo -ne "Reading: $percent%\r" done #echo "Reading: 100%" #echo $data echo $data_read if [ $match_count -eq $count ]; then echo "PASS" else echo "FAIL" fi。这是什么原因呢?
时间: 2024-02-06 11:04:01 浏览: 84
可能是由于你在循环中使用了两个不同的for语句,导致第二个for语句无法正确读取data的值。你可以将两个for语句合并成一个,像这样:
```
for ((addr=$start_addr; addr<$end_addr; addr+=4)); do
data=$(dd if=/dev/mem bs=4 count=1 skip=$(($addr/4)) 2>/dev/null | hexdump -e '/4 "%08x\n"')
echo -n "\x55\xAA\x55\xAA" | dd of=/dev/mem bs=4 count=1 seek=$(($addr)) conv=notrunc 2>/dev/null
if [ "$data" == "$data_read" ]; then
match_count=$((match_count+1))
fi
count=$((count+1))
percent=$(echo "scale=2; $count * 100 / (($end_addr - $start_addr) / 4)" | bc)
echo -ne "Reading: $percent%\r"
done
echo "Reading: 100%"
echo $data_read
if [ $match_count -eq $count ]; then
echo "PASS"
else
echo "FAIL"
fi
```
这样就可以在循环中正确读取data的值并进行比较了。
阅读全文