I was trying to diff some files, and do something if is different. But when combining with sh -c, diff can not return proper exit code.
root@i-qqixe8m2:~# cat /tmp/1
1
root@i-qqixe8m2:~# cat /tmp/2
2
root@i-qqixe8m2:~# set +x # Edited: useless cmd. But still kept here since answer below by @iBug would refer to this.
root@i-qqixe8m2:~# sh -c "diff /tmp/1 /tmp/2; echo $?;"
1c1
< 1
---
> 2
0
root@i-qqixe8m2:~# diff /tmp/1 /tmp/2; echo $?;
1c1
< 1
---
> 2
1
root@i-qqixe8m2:~#
PS. I found related question here: git diff and bash return code, but no reason provided, and comments below I believe is not the real right solution, since I don't use git here.