[英]Conditionally execute a .bashrc command
我想将Google云端硬盘附加到本地计算机(Linux)上,以便可以通过终端访问它。
经过一番谷歌搜索,我看到我可以安装google-drive-ocamlfuse来做到这一点。
当我启动机器时,我必须输入:
google-drive-ocamlfuse ~/google-drive
挂载Google云端硬盘。
为了避免每次都这样做,我将行添加到了.bashrc中。 哪个工作正常。 但是随后我打开的每个后续终端都尝试运行该行,并得到以下消息:
fuse: mountpoint is not empty
fuse: if you are sure this is safe, use the 'nonempty' mount option
我想我收到此消息是因为它正在尝试挂载已经挂载的东西。 有什么办法可以使我的.bashrc中的这一行仅在终端在会话中首次打开时才执行。 还是我可以停止警告的其他方式?
没什么大不了的,但是学习一些东西会很好。
尝试将此命令放在启动文件中:
mountpoint ~/google-drive || google-drive-ocamlfuse ~/google-drive
mountpoint
测试以查看其参数是否为安装点。 如果不是,则mountpoint
返回false并触发||
执行第二个命令。
mountpoint
是util-linux实用程序集合的一部分。
您可以将此命令放在一个外壳启动文件中,但最好将其放在一个系统启动文件中。 根据您的分发,该文件可能是/etc/rc.local
。
如果愿意,可以使用if-then
语句执行条件执行:
if ! mountpoint ~/google-drive
then
google-drive-ocamlfuse ~/google-drive
fi
在这里!
取消mountpoint的退出代码,以便仅在mountpoint返回false时才执行google-drive-ocamlfuse。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.