diff命令不工作“diff'后缺少操作数”

时间:2015-04-14 17:11:07

标签: linux bash shell diff

在diff命令中出现以下错误。请帮助我如何指定我希望在两个文件中看到差异:

#current_unavail=ranjith

root@iitmserver1 tmp]# cat /tmp/ran
ranjith
[root@iitmserver1 tmp]#

#test=$(cat /tmp/ran)

[root@iitmserver1 tmp]# diff `$current_unavail` `$test`
diff: missing operand after `diff'
diff: Try `diff --help' for more information.
[root@iitmserver1 tmp]#

1 个答案:

答案 0 :(得分:1)

diff将两个文件名作为参数,您似乎将文件内容作为第一个参数传递。您需要将脚本/命令更改为更像:

current_unavail=/tmp/unavail_cn.out
result=$(diff $current_unavail /moes/home/pharthiphan/scripts/monitoring/unavail_cn/$last_unavail)

或者,您可以使用Process Substitution将命令的输出传递给期望文件的另一个命令。例如:

diff <(echo -e "foo\nbar") <(echo -e "foo\nbaz")

然而,虽然很好地了解,但对于您当前的问题,这似乎是一种不必要的复杂程度。