run:
cd ..; \
@echo $(shell pwd)
抛出此异常:
/bin/sh: @echo: command not found
下面的代码可以工作,并输出当前目录:
run:
@echo $(shell pwd)
你知道为什么吗?
正如错误信息已经提示的那样:
/bin/sh: @echo: command not found
实际上找不到的命令是@echo
,而不是echo
。这个问题发生是因为你使用\
转义换行符时,shell接收了下面的单行字符。
cd ..; @echo [output of pwd]
cd
命令之前使用@
:run:
@cd ..; \
echo $(shell pwd)
这样,shell 将会接收到以下行:
cd ..; echo [output of pwd]
make
运行的,哪些部分是传递给shell的感到困惑。在整个cd ..; echo /whatever
字符串传递给sh
之前,$(shell pwd)
是由make
运行的。 - melpomenepwd
命令,以便由 shell 执行,而不是由 make
执行。 - JFMR