2

working with a legacy system, here I'm connecting with sqlplus to store the returned value in a variable and its worked fine with me but the problem with compearing with floating values a numeric/floating comparison and the returned value might be 0.052 or 0.0032 or integer value, as far as I know, Bash doesn't support float comparison also bc does not support in POSIX

isubsCount=$( sqlplus -s user/pass <<-EOF
    set pagesize 0;
    set feedback off;
    set verify off;
    set heading off echo off;
    select  to_char((Max(start_time_timestamp+ (2/24))- p.port_statusmoddat), 999.999) Diff
    from  test
    exit;
EOF )


if [ ${isubsCount%.*} -ge 1 ]; then

echo yes

fi

also i have tried this but it does not work,:

if (( $(echo "$isubsCount >= 1" |bc -l) )); then

echo yes

fi

1 Answers1

2

This will work using any awk in any shell on all UNIX boxes:

$ isubsCount=0.052
$ awk -v val="$isubsCount" 'BEGIN{exit !(val >= 1)}'
$ echo $?
1
$ if awk -v val="$isubsCount" 'BEGIN{exit !(val >= 1)}'; then echo "yes"; else echo "no"; fi
no

$ isubsCount=1
$ awk -v val="$isubsCount" 'BEGIN{exit !(val >= 1)}'
$ echo $?
0
$ if awk -v val="$isubsCount" 'BEGIN{exit !(val >= 1)}'; then echo "yes"; else echo "no"; fi
yes

Obviously you could change the exit statement from exit !(val >= 1) to exit (val < 1) to get the same result but I wrote it as I did just to show how you'd get the exit status you want without having to write the opposite of the condition you actually want to test for.

Ed Morton
  • 31,617