问题描述
我正在使用
mount -o bind /some/directory/here /foo/bar
我想用bash脚本检查/foo/bar
,看看是否已挂载?如果不是,则调用上面的mount命令,否则执行其他操作.我该怎么办?
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是操作系统.
CentOS is the operating system.
推荐答案
在不带参数的情况下运行mount
命令将告诉您当前的安装.从shell脚本中,您可以使用grep
和if语句检查安装点:
Running the mount
command without arguments will tell you the current mounts. From a shell script, you can check for the mount point with grep
and an if-statement:
if mount | grep /mnt/md0 > /dev/null; then
echo "yay"
else
echo "nay"
fi
在我的示例中,if语句正在检查grep
的退出代码,该代码指示是否存在匹配项.由于我不希望在匹配时显示输出,因此将其重定向到/dev/null
.
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
.
这篇关于检查目录是否用bash挂载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!