April 2018
Beginner
284 pages
7h 3m
English
Similarly, you can check files and directories using the if statement.
Let's look at an example:
#!/bin/bash mydir=/home/mydir if [ -d $mydir ] then echo "Directory $mydir exists." else echo "Directory $mydir not found." fi
We used the -d test to check if the path is a directory.
The rest of the tests work the same way.