Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In Makefiles, Is there a way to print the dollar sign ($) using @echo or $(info )?

I have been trying to print the dollar sign ($) to stdout using @echo and $(info ) used in a Makefile without success.

I can use the echo command in a bash shell on the command line to print the $ sign without any issues. But the same bash commands do not work as expected when executed from within a 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 $'

When I execute make noecho, I get:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

I also tried @echo "'$'" and @echo "\$" without success.

Is there a way to print the dollar sign ($) using @echo or $(info ) in a Makefile?

>Solution :

Double the dollar sign to stop make from interpreting it

echo $$
$(info $$)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading