CMP 如何将比较值传递到 bash 脚本中的下一行?

How does CMP pass comparison value to the next line in a bash script?

我想比较两个 framemd5(每个视频帧的解码 md5)摘要的输出。

cmp 脚本非常适合我。 我对编码几乎一无所知,所以我想对正在发生的事情进行自我教育,但我无法从 SO 或谷歌搜索中弄清楚。

脚本似乎需要我提供更多输入,就像我必须规定(为糟糕的伪代码道歉)

cmp file1 file 2
if cmp produces a difference;then
else 

似乎只要输入 "if cmp file1 file 2" 就自动生成了 YES 或 NO 的等价物,并为 then、else 等存储该信息?

if 将评估任何返回零或非零状态的命令,如果状态为 0 则执行 then 分支,否则执行 else 分支,因此您可以简单地写:

 if cmp -s file1 file; then
    echo "files are equal"
 else
     echo "files are different"
 fi