我希望两个外部HD在同时连接时立即同步。
我安装了LaunchControl,它将在安装某些东西后立即运行bash脚本。该脚本应检查是否有两个称为foo
和bar
的设备,然后才能执行某些操作。
这就是我所拥有的:
if mount | grep "/Volumes/foo" > /dev/null; then
echo "One is connected"
fi
每次为bar
添加第二张支票的尝试均失败。这是我尝试过的:
if mount | [grep "/Volumes/foo" > /dev/null] && [grep "/Volumes/bar" > /dev/null]; then
echo "Both are connected"
fi
答案 0 :(得分:1)
您的工作代码在对[]
的调用中没有grep
,为什么您认为在进行多个测试时需要添加代码?
if mount | grep "/Volumes/foo" > /dev/null && mount | grep "/Volumes/bar" > /dev/null; then
echo "Both are connected"
fi
您可以将/dev/null
选项用于-q
,而不是重定向到grep
。
if mount | grep -q "/Volumes/foo" && mount | grep -q "/Volumes/bar"; then
echo "Both are connected"
fi