gpt4 book ai didi

shell - 在 makefile 中运行脚本

转载 作者:行者123 更新时间:2023-12-02 01:37:24 44 4
gpt4 key购买 nike

我想在这样的 makefile 中运行一个脚本

    all: a b
a:
cd ~/trials; \
. ./sx.sh
b:
echo $(bn)

sx.sh 这样做
    export bn=1

发出 make 命令时,我在终端中没有看到该变量。我的目标是在为这些脚本特定设置编译我的项目之前运行脚本。

最佳答案

您不能假设 make 发出的命令都由同一个 shell 实例化处理。 Make 不会打开 shell 并逐一提供命令,也不会将命令保存到文件中,然后再将其提供给 shell。它通常为每个命令生成一个 shell,如下所示:

$(SHELL) -c 'cd ~/trials; . ./sx.sh'

这意味着您不能改变环境并让它由以后的命令继承。

最好的方法是使用 make 变量来存储您希望传递给命令的细节,并在适当的地方使用这些变量。

关于shell - 在 makefile 中运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30481111/

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