# Help with Script: If diff between files is nothing then set a variable

**URL:** <https://community.unix.com/t/help-with-script-if-diff-between-files-is-nothing-then-set-a-variable/221144>\
**Category:** Shell Programming and Scripting\
**Created:** [November 18, 2008, 5:34pm UTC](https://community.unix.com/t/help-with-script-if-diff-between-files-is-nothing-then-set-a-variable/221144 "2008-11-18T17:34:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuathan](https://community.unix.com/user_avatar/community.unix.com/tuathan/32/4617_2.png) [@tuathan](https://community.unix.com/u/tuathan)\
**Post date:** [November 18, 2008, 5:34pm UTC](https://community.unix.com/t/help-with-script-if-diff-between-files-is-nothing-then-set-a-variable/221144/1 "2008-11-18T17:34:25Z")

</div>

how about a script that compares 2 files using diff (or similar) and if they are then same then set a variable, v1=int else v1=0.

thanks

---

<div class="post-metadata">

**Author:** ![danmero](https://community.unix.com/letter_avatar/danmero/32/6_22734026db12803ebb3e059622ac3534.png) [@danmero](https://community.unix.com/u/danmero)\
**Post date:** [November 18, 2008, 6:49pm UTC](https://community.unix.com/t/help-with-script-if-diff-between-files-is-nothing-then-set-a-variable/221144/2 "2008-11-18T18:49:55Z")

</div>

Use diff exit code

```nohighlight
diff file1 file2 > /dev/null
v1=$?
echo $v1

```

---

<div class="post-metadata">

**Author:** ![tuathan](https://community.unix.com/user_avatar/community.unix.com/tuathan/32/4617_2.png) [@tuathan](https://community.unix.com/u/tuathan)\
**Post date:** [November 18, 2008, 7:23pm UTC](https://community.unix.com/t/help-with-script-if-diff-between-files-is-nothing-then-set-a-variable/221144/3 "2008-11-18T19:23:00Z")

</div>

thanks this is very useful for what i want to do 🙂
