for example:
# I want to judge the value of $1 which should be $2<$1<$3.
temp0=`echo "$1 - $2" | bc`
temp1=`echo "$1 - $3" | bc`
if [[ $temp0 =~ 'how to match a positive number' && $temp1 =~ 'how to match a negative number' ]] ; then
echo OK
else
echo False
fi
sulti
August 30, 2011, 3:51am
2
Try this:
if [ `echo "$1 > $2" | bc -l` -eq 1 -a `echo "$1 < $3" | bc -l` -eq 1 ]; then
echo OK
else
echo False
fi
2 Likes
yazu
August 30, 2011, 3:54am
3
ksh93, bash, zsh:
if (( $2 < $1 && $1 < $3)); then
echo Ok
else
echo False
done
===
Well, bash doesn't work with floating numbers. Then
if [[ ! $temp0 =~ ^- && $temp1 =~ ^- ]]; then
...
2 Likes
sulti
August 30, 2011, 4:00am
4
Above is true, when Your number is in this format:
0,1
It's not working when You have dot in number (like in bc standard):
0.1
1 Like
Thank you guys~
The advices all of your give me much help.
qcmao
August 30, 2011, 5:49am
6
In this code
if [ `echo "$1 > $2" | bc -l` -eq 1 -a `echo "$1 < $3" | bc -l` -eq 1 ]
the meaning of parameter "-a" is "and" operator?
1 Like