如何检查macOS中是否安装了两个设备?

时间:2020-08-06 18:47:33

标签: bash macos

我希望两个外部HD在同时连接时立即同步。

我安装了LaunchControl,它将在安装某些东西后立即运行bash脚本。该脚本应检查是否有两个称为foobar的设备,然后才能执行某些操作。

这就是我所拥有的:

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

1 个答案:

答案 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