bash的检查目录存在时挂NFS挂载下降 [英] bash checking directory existence hanging when NFS mount goes down
问题描述
我有一个.bash_profile中的脚本,基于目录存在设置了一些别名对我来说:
I have a .bash_profile script that sets up some aliases for me based on directory existence:
if [ -d /home/user/games ] ; then
alias cdgames='cd /home/user/games'
fi
其中一个目录是在NFS挂载 - 如果文件管理器不响应苏 - 用户
会继续留在这一行中的.bash_profile
One of these directory is on an NFS mount - if the filer becomes unresponsive su - user
will hang on this line in .bash_profile.
有没有什么办法来检查在bash目录的存在,而不会导致挂起如果目录被安装到无响应的文件管理器?
Is there any way to check existence of a directory in bash without causing a hang if the directory is mounted to an unresponsive filer?
推荐答案
作为文件夹应该出现在/ etc挂载设备/ MTAB你可以尝试这样的事情
As the folder should appear as a mount device in /etc/mtab you can try something like this
if grep -q '/home/user/games' /etc/mtab ; then
alias cdgames='cd /home/user/games'
fi
这方法是有点粗鲁,但它适用于大多数的情况。
This approach is a bit rude but it works for most of the situations.
这篇关于bash的检查目录存在时挂NFS挂载下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!