本文介绍了击:用差异的结果,在if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个简单的Bash脚本当文件夹已被修改,以检测。

这是一件很接近:

  LS -lR $ DIR>一个
LS -lR $ DIR> bDIFF = $(差异A B)
如果[$ DIFF -ne 0]
然后
    回声目录被修改

不幸的是,if语句输出错误:[:-ne:一元运算符预期。

我不知道有什么不对我的脚本,会有人请能帮帮我吗?

非常感谢你!

Jary


解决方案

  LS -lR $ DIR>一个
LS -lR $ DIR> bDIFF = $(差异A B)
如果[$ DIFF!=]
然后
    回声目录被修改
科幻

I am writing a simple Bash script to detect when a folder has been modified.

It is something very close to:

ls -lR $dir > a
ls -lR $dir > b

DIFF=$(diff a b) 
if [ $DIFF -ne 0 ] 
then
    echo "The directory was modified"

Unfortunately, the if statement prints an error: [: -ne: unary operator expected

I am not sure what is wrong with my script, would anyone please be able to help me?

Thank you very much!

Jary

解决方案
ls -lR $dir > a
ls -lR $dir > b

DIFF=$(diff a b) 
if [ "$DIFF" != "" ] 
then
    echo "The directory was modified"
fi

这篇关于击:用差异的结果,在if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 19:04