我需要 cd 到特定目录,然后简单地运行go run main.go并启动我的应用程序。我有以下内容:stand-app: | $(info Booting up the app for local testing) cd $(PWD)/cmd/myapp go run main.go当我运行目标时,我得到以下信息:go run main.gostat main.go: no such file or directorymake: *** [stand-app] Error 1但是位置是正确的,我可以简单地通过 cd 到该目录并运行命令来执行这些步骤。我哪里错了?谢谢
1 回答
人到中年有点甜
TA贡献1895条经验 获得超7个赞
配方中的每个逻辑行都在不同的 shell 中运行。当前工作目录是 shell 的一个属性;当 shell 消失时,对工作目录的任何更改也会消失。所以,你cd ...
是一个空操作:它改变了那个 shell 中的工作目录,然后 shell 退出,下一个 shell 从原来的工作目录开始。
将这两行合并为一条逻辑行;也许是这样的:
stand-app: $(info Booting up the app for local testing) cd $(PWD)/cmd/myapp && go run main.go
只是提醒一下:PWD
制作起来并不特别。如果您从中调用 make 的 shell 设置了它,它将有一个值,如果您从中调用 make 的 shell 没有设置它,它将没有值(或者如果它在父 shell 中设置不正确,它将有错误的值). 您可能想改用 make 的CURDIR
变量:
stand-app: $(info Booting up the app for local testing) cd '$(CURDIR)/cmd/myapp' && go run main.go
- 1 回答
- 0 关注
- 305 浏览
添加回答
举报
0/150
提交
取消