Member-only story
100 Days of DevOps — Day 52-Conditional Testing in Shell
3 min readApr 4, 2019
Welcome to Day 52 of 100 Days of DevOps, Focus for today is Conditional Testing in Bash.
Today I am going to discuss test command
test - check file types and compare values
- In your script you generally see, it starts with left bracket( [ ) when need to perform some testing.
Exit Status
- In bash after running any command, the exit status is returned and stored in variable $?
0 --> good
1 or some other code --> issue
Test Integers
# test 1 -eq 1;echo $?0
- Here we are trying to check if 1 is equal to 1 and then perform command chaining to merge two command
- As mentioned above exit status 0 mean good
# test 1 -eq 2;echo $?1
- Exit status other than zero, in the above case, means some issue
- The same way we can test less than or greater than or not equal to
# less then
# test 1 -lt 2;echo $?0OR# greater then# test 1 -gt 2;echo $?1# not equal toOR # test 1 -ne 2;echo $?0