The mountpoint manual states that it:
checks if a given directory or file is specified in the / proc / self / mountinfo file.
The mount manual says that:
Listing mode is only supported for backward compatibility. For a more reliable and customizable output, use findmnt (8), especially in your scripts.
So, the correct command to use is findmnt , which itself is part of the util-linux package and, according to the manual:
able to search in / etc / fstab, / etc / mtab or / proc / self / mountinfo
Therefore, he is looking for more things than mountpoint . It also provides a convenient option:
-M, - mount point path
Explicitly define the file or directory of the mount point. See Also --target.
In conclusion, to check if a directory is installed using bash, you can use:
if [[ $(findmnt -M "$FOLDER") ]]; then echo "Mounted" else echo "Not mounted" fi
Example:
mkdir -p /tmp/foo/{a,b} cd /tmp/foo sudo mount -o bind ab touch a/file ls b/
Sheljohn Sep 03 '17 at 16:38 on 2017-09-03 16:38
source share