I am using
mount -o bind /some/directory/here /foo/bar
I want to check /foo/bar though with a bash script, and see if its been mounted? If not, then call the above mount command, else do something else. How can I do this?
CentOS is the operating system.
Running the
mountcommand without arguments will tell you the current mounts. From a shell script, you can check for the mount point withgrepand an if-statement:In my example, the if-statement is checking the exit code of
grep, which indicates if there was a match. Since I don’t want the output to be displayed when there is a match, I’m redirecting it to/dev/null.