加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

makefile – bash:PWD和CURDIR有什么区别?

发布时间:2020-12-16 09:21:49 所属栏目:百科 来源:网络整理
导读:我的问题 我使用Makefile来运行docker run target,它需要当前工作目录作为其参数之一. 我使用$(PWD)或$(CURDIR): build: Dockerfile docker run ... $(PWD) or $(CURDIR) 它们似乎产生了相同的价值.我不知道是否有一个微妙的差异可以咬我以后,所以我想知道
我的问题

我使用Makefile来运行docker run target,它需要当前工作目录作为其参数之一.

我使用$(PWD)或$(CURDIR):

build: Dockerfile
        docker run ... <$(PWD) or $(CURDIR)>

它们似乎产生了相同的价值.我不知道是否有一个微妙的差异可以咬我以后,所以我想知道每个的确切定义.

我试过了什么

> STFW
>男人做

我的问题

Makefile中$(PWD)和$(CURDIR)有什么区别?

解决方法

TL; DR

使用CURDIR.

为什么?

首先,感谢Renaud Pacalet his comment.

CURDIR

引用GNU Make Manual:

CURDIR

Set to the absolute pathname of the current working directory.

For your convenience,when GNU make starts (after it has processed any -C options) it sets the variable CURDIR to the pathname of the current working directory. This value is never touched by make again: in particular note that if you include files from other directories the value of CURDIR does not change. The value has the same precedence it would have if it were set in the makefile (by default,an environment variable CURDIR will not override this value). Note that setting this variable has no impact on the operation of make (it does not cause make to change its working directory,for example).

PWD

在Make手册中没有提到PWD.快速环境| grep PWD发现它是由环境设置的(在我的例子中是zsh). GNU关于Special Shell Variables
的说明指出:

PWD

Posix 1003.1-2001 requires that cd and pwd must update the PWD environment variable to point to the logical name of the current directory,but traditional shells do not support this. This can cause confusion if one shell instance maintains PWD but a subsidiary and different shell does not know about PWD and executes cd; in this case PWD points to the wrong directory. Use “pwd' rather than$PWD’.

由于保证CURDIR可以在Make中工作,因此可能从shell继承,前者应该是首选.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读