gpt4 book ai didi

bash - 可以在 makefile 中使用 bash 严格模式吗?

转载 作者:行者123 更新时间:2023-11-29 09:31:31 25 4
gpt4 key购买 nike

您可以显式设置 makefile 使用的 shell:

SHELL := /bin/bash

这个 #!/bin/bash 是否会替换为 bash 严格模式 header 的其余部分?

set -euo pipefail
IFS=$'\n\t'

http://redsymbol.net/articles/unofficial-bash-strict-mode/

最佳答案

make 规则中的每一行都是一个新的子 shell,因此没有 header 不会直接继承。

一个选择是在你的 make 规则的每一行前加上前缀:

my-rule:
set -euo pipefail; \
IFS=$'\n\t'; \
<the rest of your line>

另一种选择是在您的 make 规则刚刚调用的 shell 脚本中使用 bash 严格模式:

my-rule:
./my-script-with-bash-strict-mode.sh

另一种选择是将所有规则包装在带有该 header 的规则之下。这假设您只有一个进入您的 makefile 的入口点。

my-top-level-rule:
set -euo pipefail; \
IFS=$'\n\t'; \
${MAKE} <my-other-rule>

关于bash - 可以在 makefile 中使用 bash 严格模式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37146710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com