开发者

ksh conditional

开发者 https://www.devze.com 2023-01-31 07:55 出处:网络
There is something simple I am over looking. if [ ${FILEDATE} -gt ${MIN} ]; then echo $MAX fi The above code works, but not this:

There is something simple I am over looking.

if [ ${FILEDATE} -gt ${MIN} ]; then
    echo $MAX
fi

The above code works, but not this:

if [ ${FILEDATE} -gt ${MIN} ||  ${FILEDATE} -lt ${MAX}]; then
    echo $MAX
fi

There must be some syntax problem, but th开发者_高级运维e references I have found look identical to what I have.


[ (on my system it is at /usr/bin/[) is actually a program or builtin which expects an expression just like test(1) does. The peculiarity with [ is, that it has to be wrapped up with a closing ].

So calling [ and combining different expressions is possible by using && and || operators from the shell:

if [ ${FILEDATE} -gt ${MIN} ] || [ ${FILEDATE} -lt ${MAX} ]; then #... Should work just fine.

You might also consider to put the variable expansions inside "" to get nice behavior even if some variable isn't defined ;)

See also: Unix test.

0

精彩评论

暂无评论...
验证码 换一张
取 消