如何测试 OSX 上的 bash 中是否存在 .app(应用程序目录)?

Pau*_*lCo 2 macos bash

我想通过 bash 脚本测试文件或目录是否存在:

    if [ -f "$file" -o -d "$file" ]; then
        # Do things
    fi
Run Code Online (Sandbox Code Playgroud)

但此测试不适用于应用程序文件(.app),我在测试手册页上找不到答案,并且认为 .app 被视为 osx 上的文件夹。

Ste*_*anS 5

检查目录是否存在:

if [ -d "$<app name>.app" ]; then
  # Control will enter here if $<app name>.app exists.
fi
Run Code Online (Sandbox Code Playgroud)

检查目录是否不存在:

if [ ! -d "$<app name>.app" ]; then
  # Control will enter here if $<app name>.app doesn't exist.
fi
Run Code Online (Sandbox Code Playgroud)