June 2017
Beginner
502 pages
11h 26m
English
The NOT operator is used to test whether an expression is true and holds true when the expression is false:
[! expression ]
Let's go back to one of our previous scripts and make it more user-friendly:
#!/bin/bash echo "Hello user, please give me a number between 10 and 12: " read user_input if [ ! ${user_input} -eq11 ]thenecho "The number ${user_input} is not what we are looking for..."elseecho "Great! The number ${user_input} is what we were looking for!"fi
What we are doing here is asking the user for a number between 10 and 12. We read the value from its input and evaluate it: if the user inputs a value that is not equal to 11, then we write a boo sentence; otherwise, we have found our number. Do not worry; we will have ...
Read now
Unlock full access