Skip to main content
deleted 23 characters in body
Source Link
jesse_b
  • 41.6k
  • 14
  • 109
  • 163

If you want to use num2 as is you could use awk:

awk -v num1="$num1" -v num2="$num2" 'BEGIN{if (num1<num2) {exit 1} else {exit 0}num1<=num2}' 

This will compare the two numbers and exit 1 if num1 is less than num2 or exit 0 otherwise.

Note: this will exit 1 if num1 and num2 are equal which is the same behavior you would see from bc in that case, if you want it to exit 0 in that case you will need to use < instead of <=.

If you want to use num2 as is you could use awk:

awk -v num1="$num1" -v num2="$num2" 'BEGIN{if (num1<num2) {exit 1} else {exit 0}}' 

This will compare the two numbers and exit 1 if num1 is less than num2 or exit 0 otherwise.

If you want to use num2 as is you could use awk:

awk -v num1="$num1" -v num2="$num2" 'BEGIN{exit num1<=num2}' 

This will compare the two numbers and exit 1 if num1 is less than num2 or exit 0 otherwise.

Note: this will exit 1 if num1 and num2 are equal which is the same behavior you would see from bc in that case, if you want it to exit 0 in that case you will need to use < instead of <=.

Source Link
jesse_b
  • 41.6k
  • 14
  • 109
  • 163

If you want to use num2 as is you could use awk:

awk -v num1="$num1" -v num2="$num2" 'BEGIN{if (num1<num2) {exit 1} else {exit 0}}' 

This will compare the two numbers and exit 1 if num1 is less than num2 or exit 0 otherwise.