shell -- 比较两个文件是否相同

[HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED][HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED][HTML_REMOVED] [HTML_REMOVED] [HTML_REMOVED]说明[HTML_REMOVED] [HTML_REMOVED]在写代码进行迭代的时候,想通过 shell 判断当前后输出的文件相同时则停止,就网上找了个脚本进行了修改[HTML_REMOVED] [HTML_REMOVED]脚本来源:[HTML_REMOVED]https://blog.csdn.net/u010783148/article/details/73691154[HTML_REMOVED][HTML_REMOVED] [HTML_REMOVED] [HTML_REMOVED]脚本[HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED][HTML_REMOVED][HTML_REMOVED][HTML_REMOVED] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33[HTML_REMOVED][HTML_REMOVED][HTML_REMOVED][HTML_REMOVED][HTML_REMOVED][HTML_REMOVED][HTML_REMOVED][HTML_REMOVED][HTML_REMOVED]#!/bin/bash[HTML_REMOVED]

[HTML_REMOVED]# ScriptName: file_diff.sh[HTML_REMOVED]

[HTML_REMOVED]echo[HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED]usage: -[HTML_REMOVED][HTML_REMOVED]$0[HTML_REMOVED][HTML_REMOVED] file1 file2[HTML_REMOVED][HTML_REMOVED]

[HTML_REMOVED]file1[HTML_REMOVED][HTML_REMOVED]=[HTML_REMOVED][HTML_REMOVED]$1[HTML_REMOVED]

[HTML_REMOVED]file2[HTML_REMOVED][HTML_REMOVED]=[HTML_REMOVED][HTML_REMOVED]$2[HTML_REMOVED]

[HTML_REMOVED]if[HTML_REMOVED] [HTML_REMOVED][[HTML_REMOVED] -f [HTML_REMOVED]$file1[HTML_REMOVED] [HTML_REMOVED]][HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED][HTML_REMOVED][HTML_REMOVED] [HTML_REMOVED][[HTML_REMOVED] -f [HTML_REMOVED]$file2[HTML_REMOVED] [HTML_REMOVED]][HTML_REMOVED]

[HTML_REMOVED]then[HTML_REMOVED]

diff <span class="nv">$file1</span> <span class="nv">$file2</span> &gt; /dev/null

<span class="k">if</span> <span class="o">[</span> <span class="nv">$?</span> !<span class="o">=</span> <span class="m">0</span> <span class="o">]</span>

<span class="k">then</span>

    <span class="nb">echo</span> <span class="s2">&quot;Different!&quot;</span>

<span class="k">else</span>

    <span class="nb">echo</span> <span class="s2">&quot;Same!&quot;</span>

<span class="k">fi</span>

[HTML_REMOVED]else[HTML_REMOVED]

<span class="nb">echo</span> <span class="s2">&quot;</span><span class="nv">$file1</span><span class="s2"> or </span><span class="nv">$file2</span><span class="s2"> does not exist, please check filename.&quot;</span>

[HTML_REMOVED]fi[HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED] [HTML_REMOVED][HTML_REMOVED][HTML_REMOVED]

[HTML_REMOVED]