July 2018
Beginner
264 pages
8h 9m
English
If a single level of if statements is not enough and you would like to have additional logic within an if statement, you can create nested conditional statements. This can be done in the following way:
#!/bin/bashUSER_AGE=18AGE_LIMIT=18NAME="Bob" # Change to your username if you want to execute the nested logicHAS_NIGHTMARES="true"if [ "${USER}" == "${NAME}" ]; then if [ ${USER_AGE} -ge ${AGE_LIMIT} ]; then if [ "${HAS_NIGHTMARES}" == "true" ]; then echo "${USER} gets nightmares, and should not see the movie" fi fielse echo "Who is this?"fi
Read now
Unlock full access