在 Xcode 中运行没有环境变量的 shell 脚本?

Eon*_*nil 5 shell xcode environment-variables

Xcode 在运行 shell 脚本时设置各种与构建相关的环境变量。有没有办法在不设置这些变量的情况下运行 shell 脚本?

Eon*_*nil 5

我得到了一个解决方案。Run Script Phase在目标阶段 使用此方法: https://serverfault.com/questions/176966/how-to-continue-execution-of-shell-script-after-calling-other-shell-script-with/176976#176976

这些 shell 命令运行以下命令,忽略当前环境中的变量。

env -i <command>
exec -c <command>
Run Code Online (Sandbox Code Playgroud)

作为一个例子,我使用了这个脚本:

env -i ./makeall.sh
Run Code Online (Sandbox Code Playgroud)

这会禁用所有 Xcode 的预定义变量,因此脚本不受 Xcode 配置的影响,但它的用处也较小,因为我们无法使用与构建相关的 Xcode 路径。

但是,您可以像此脚本一样传递特定的 Xcode 变量。

build()
{
    # Don't know why, however, the environment variable passed to external script even with "env -i".
    env -i ./makeall.sh "${SYMROOT}"
}

build
Run Code Online (Sandbox Code Playgroud)