bash:PWD和CURDIR有什么区别? [英] bash: What is the difference between PWD and CURDIR?

查看:381
本文介绍了bash:PWD和CURDIR有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use a Makefile to run a docker run target, which needs the current working directory as one of its parameters.

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

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

他们似乎正在产生相同的价值.我不知道以后是否会有细微的差别可以咬我,所以我想知道它们各自的确切定义.

They seem to be producing the same value. I don't know if there's a subtle difference that can bite me later, so I want to know the exact definition of each of them.

  • STFW
  • man make

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

What is the difference between $(PWD) and $(CURDIR) in a Makefile?

推荐答案

TL; DR

使用CURDIR.

首先,感谢 Renaud Pacalet 感谢引用 GNU Make手册:

CURDIR

设置为当前工作目录的绝对路径名.

Set to the absolute pathname of the current working directory.

为方便起见,当GNU make启动时(在处理完所有-C选项之后),它将变量CURDIR设置为当前工作目录的路径名.该值永远不会再被make触及:特别要注意的是,如果包含其他目录中的文件,则CURDIR的值不会更改.该值具有与在makefile中设置的优先级相同的优先级(默认情况下,环境变量CURDIR不会覆盖该值).请注意,设置此变量不会影响make的操作(例如,不会导致make更改其工作目录).

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

在制造"手册中没有引用PWD.快速env | grep PWD发现它是由环境(在我的情况下为zsh)设置的. GNU关于特殊Shell变量的注释 声明:

PWD

There's no reference to PWD in the Make manual. A quick env | grep PWD found that it was set by the environment (in my case, zsh). GNU's notes about Special Shell Variables state that:

PWD

PWD

Posix 1003.1-2001要求cd和pwd必须更新PWD环境变量以指向当前目录的逻辑名称,但是传统的shell不支持此功能.如果一个外壳程序实例维护PWD,而一个附属且不同的外壳程序不知道PWD并执行cd,则可能引起混乱.在这种情况下,PWD指向错误的目录.使用``pwd ' rather than $ 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'.

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

Since CURDIR is guaranteed to work in Make in PWD might be inherited from the shell, the former should be preferred.

这篇关于bash:PWD和CURDIR有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆