Answer is zero (0). Shell simple compared two number and returned result as true or false. Is 5 is less than 2? No. So 0 is returned. The Boolean (logical data) type is a primitive data type having one of two values
- True
- False
In shell:
- 0 value indicates false.
- 1 or non-zero value indicate true.
Examples
| Operator | Example | Description | True / False | Evaluates To |
|---|---|---|---|---|
| 5 > 12 | echo $(( 5 > 12 )) | Is 5 greater than 12? | No (false) | 0 |
| 5 == 10 | echo $(( 5 == 10 )) | Is 5 equal to 10? | No (false) | 0 |
| 5 != 2 | echo $(( 5 != 2 )) | 5 is not equal to 2? | Yes (true) | 1 |
| 1 < 2 | echo $(( 1 < 2 )) | Is 1 less than 2? | Yes (true) | 1 |
| 5 == 5 | echo $(( 5 == 5 )) | Is 5 equal to 5? | Yes (true) | 1 |
Now, it makes no sense to use echo command for comparisons. But, when you compare it with some value it becomes very useful.
test command syntax
test condition && true-command || false-command
Type the following command at a shell prompt (is 5 greater than 2? ):
test 5 -gt 2 && echo "Yes" or test 1 -lt 2 && echo "Yes"
echo Options
| Options | Description |
| -n | do not print the trailing newline. |
| -e | enable interpretation of backslash escapes. |
| \b | backspace |
| \\ | backslash |
| \n | new line |
| \r | carriage return |
| \t | horizontal tab |
| \v | vertical tab |
No comments:
Post a Comment