我想在IF子句中使用数学表达式 - 类似这样:
#!/bin/sh
now=`date +%H%M`
if [ $now % 5 -gt 0 ] ; then
exit
fi
perl ...
对此有什么正确的语法?
答案 0 :(得分:3)
if expr $now % 5 \> 0 > /dev/null; then ...
或
if test $(( $now % 5 )) -gt 0; then ...
请注意,您根本不需要if子句,并且可以执行
test $(( $now % 5 )) -gt 0 && exit
答案 1 :(得分:1)
假设bash:
if (( now%5 > 0 )); then ...