[英]bash checking directory existence hanging when NFS mount goes down
I have a .bash_profile script that sets up some aliases for me based on directory existence: 我有一个.bash_profile脚本,该脚本根据目录的存在为我设置了一些别名:
if [ -d /home/user/games ] ; then
alias cdgames='cd /home/user/games'
fi
One of these directory is on an NFS mount - if the filer becomes unresponsive su - user
will hang on this line in .bash_profile. 这些目录之一位于NFS挂载上-如果文件管理器无响应,则su - user
将挂在.bash_profile中的此行上。
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? 如果目录挂载到无响应的文件管理器,有什么方法可以检查bash中目录的存在而不会导致挂起?
As the folder should appear as a mount device in /etc/mtab you can try something like this 由于该文件夹应显示为/ etc / mtab中的挂载设备,因此您可以尝试这样的操作
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. 这种方法有点粗鲁,但适用于大多数情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.