Skip to main content
added 15 characters in body
Source Link
Ed Morton
  • 36k
  • 6
  • 25
  • 60

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 negatewrite the opposite of the condition you actually want to test for.

$ 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 negate the condition you actually want to test for.

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.

Source Link
Ed Morton
  • 36k
  • 6
  • 25
  • 60

$ 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 negate the condition you actually want to test for.