ksh conditional
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.
精彩评论