Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make file echo displaying "$PATH" string

I am trying to force make file to display next string:

"Please execute next commands: setenv PATH /usr/local/greenhills/mips5/linux86:$PATH" 

The problem is with "$PATH". Command

@echo "setenv PATH /usr/local/greenhills/mips5/linux86:$PATH" 

cause a result

"setenv PATH /usr/local/greenhills/mips5/linux86:ATH" 

any combinations of escape characters, quotes, "$(shell echo " didn't get required results...

Any suggestions?

like image 685
BaruchLi Avatar asked Sep 14 '10 09:09

BaruchLi


People also ask

How do you make an echo file?

Creating a File with echo Command To create a new file run the echo command followed by the text you want to print and use the redirection operator > to write the output to the file you want to create.

How can I get PWD in makefile?

You can use shell function: current_dir = $(shell pwd) . Or shell in combination with notdir , if you need not absolute path: current_dir = $(notdir $(shell pwd)) .

What does @echo mean in makefile?

The ' @ ' is discarded before the line is passed to the shell. Typically you would use this for a command whose only effect is to print something, such as an echo command to indicate progress through the makefile: @echo About to make distribution files.


2 Answers

In the manual for GNU make, they talk about this specific example when describing the value function:

The value function provides a way for you to use the value of a variable without having it expanded. Please note that this does not undo expansions which have already occurred; for example if you create a simply expanded variable its value is expanded during the definition; in that case the value function will return the same result as using the variable directly.

The syntax of the value function is:

 $(value variable) 

Note that variable is the name of a variable; not a reference to that variable. Therefore you would not normally use a ‘$’ or parentheses when writing it. (You can, however, use a variable reference in the name if you want the name not to be a constant.)

The result of this function is a string containing the value of variable, without any expansion occurring. For example, in this makefile:

 FOO = $PATH   all:          @echo $(FOO)          @echo $(value FOO) 

The first output line would be ATH, since the “$P” would be expanded as a make variable, while the second output line would be the current value of your $PATH environment variable, since the value function avoided the expansion.

like image 91
gsingh2011 Avatar answered Oct 13 '22 19:10

gsingh2011


The make uses the $ for its own variable expansions. E.g. single character variable $A or variable with a long name - ${VAR} and $(VAR).

To put the $ into a command, use the $$, for example:

all:   @echo "Please execute next commands:"   @echo 'setenv PATH /usr/local/greenhills/mips5/linux86:$$PATH' 

Also note that to make the "" and '' (double and single quoting) do not play any role and they are passed verbatim to the shell. (Remove the @ sign to see what make sends to shell.) To prevent the shell from expanding $PATH, second line uses the ''.

like image 43
Dummy00001 Avatar answered Oct 13 '22 18:10

Dummy00001