linux - diff 命令不工作 "missing operand after ` diff'"

标签 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]#

最佳答案

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")

但是,虽然很高兴了解这一点,但对于您当前的问题来说,这似乎是不必要的复杂程度。

关于linux - diff 命令不工作 "missing operand after ` diff'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29633449/

相关文章:

regex - 如何使用 sed 命令删除一行中除前三个字符以外的所有字符?

bash - 摄氏度到开尔文温度转换 bash 脚本

java - IOException:关闭文件流时权限被拒绝

linux - 如何在Windows上生成Linux的可执行文件?

linux - systemctl disable name.service 在重启后不会持续存在

linux - 使用多个 CPU 内核优化目录中的图像

bash - ${VAR :=value} in a bash script 的结果是什么

bash - 如何使 GETOPTS 选项字符串选项区分大小写?

python - 在出现时将 Flask 控制台日志写入 HTML 模板

php - 无法交换加密 key