在Makefiles中,有没有一种方法可以使用@echo或$(info)打印美元符号($)



我一直试图使用Makefile中使用的@echo$(info )将美元符号($(打印到stdout,但没有成功。

我可以在命令行上使用bash shell中的echo命令来打印$符号,而不会出现任何问题。但是,当从Makefile中执行相同的bash命令时,它们不会像预期的那样工作。

以下是我的测试Makefile:

noecho:
$(info Print the dollar sign using info: $)
@echo You only see this!  You DO NOT see the echo command printed above.
@echo Remember echo is a shell command. 
@echo You may need to escape special characters, like \
@echo 'Or put put text in single quotes! No need to escape special characters like .'
@echo 
@echo "Enclosing characters in single quotes (') preserves the literal value of "
@echo 'each character within the quotes. A single quote may not occur between '
@echo 'single quotes, even when preceded by a backslash.'
@echo
@echo "Double quotes can also be used in most cases."
@echo "Enclosing characters in double quotes (") preserves the literal value of "
@echo "all characters within the quotes, with the exception of $, `, \, and, "
@echo "when history expansion is enabled, !"
@echo 'Printing the $'

当我执行make noecho时,我得到:

rob$ make noecho
Print the dollar sign using info: 
You only see this! You DO NOT see the echo command printed above.
Remember echo is a shell command.
You may need to escape special characters, like 
Or put put text in single quotes! No need to escape special characters like .
Enclosing characters in single quotes (') preserves the literal value of 
each character within the quotes. A single quote may not occur between 
single quotes, even when preceded by a backslash.
Double quotes can also be used in most cases.
Enclosing characters in double quotes (") preserves the literal value of 
all characters within the quotes, with the exception of  `, , and, 
when history expansion is enabled, !
/opt/local/bin/bash: -c: line 1: unexpected EOF while looking for matching `''
/opt/local/bin/bash: -c: line 2: syntax error: unexpected end of file
make: *** [noecho] Error 2

我还尝试了@echo "'$'"@echo "$",但没有成功。

有没有办法在Makefile中使用@echo$(info )打印美元符号($(?

将美元符号加倍以阻止make对其进行解释

echo $$
$(info $$)

最新更新