June 2017
Beginner
502 pages
11h 26m
English
The AND operator tests the success of two or more expressions and holds true if all the conditions are true. This comes in handy to make our script a bit more complex so that we must pass at least a couple of conditions to make something trigger:
#!/bin/bash echo "Hello user, please give me a number between 10 and 20: " read user_input if [ ${user_input} -ge 10 ] && [ ${user_input} -le 20 ]thenecho "Great! The number ${user_input} is what we were looking for!"elseecho "The number ${user_input} is not what we are looking for..."fi
In this case, we ask for a couple of conditions that must hold true at the same time: the number given by the user must be equal or greater than 10 and lesser or equal than 20. Let's see:
zarrelli:~$ ...
Read now
Unlock full access