Reputation: 822
this is a really simple issue, but I am struggling to figure out how to do it. I have a makefile, and in the make file I have the following line:
echo "java packet.Program $1 $2 $3 $4" > programScript
My question is this: How do I make this line print exactly what is in the quotes? Right now, it keeps trying to interpret $1, $2, $3, $4 as parameters. I want the makefile, when run, to echo exactly "java packet.Program $1 $2 $3 $4" char for char. The '$' are giving me an issue.
Thanks.
Edit:
To clarify the issue. When I type "echo 'java packet.Program $1 $2 $3 $4' > programScript" into the terminal, it prints it exactly how it should. But when I put the same line into my makefile file, and run "make", it doesnt print anything after "java packet.Program".
Upvotes: 1
Views: 3020
Reputation: 241971
make
does not attempt to parse command lines, so "$name"
and '$name'
are treated the same by make
; in both cases, the $name
will be substituted with the value of the make
variable $(name)
. In neither case will the shell see the $
.
If you want to insert a literal $
in a command in a makefile, you need to write $$
.
So, for example:
show_a_dollar:
echo '$$a'
show_a_variable:
echo "$$a"
In the first make
rule, the resulting action is:
echo '$a'
which will echo, literally, $a
. In the second, the resulting action is
echo "$a"
which will echo the value of the environment variable a
.
So you need to consider both make
expansion rules, which require you to double the $
to $$
, and shell expansion rules, which require the command-line argument to be within single-quotes:
echo 'java packet.Program $$1 $$2 $$3 $$4' > programScript
Upvotes: 3
Reputation: 106
Use either single quote
echo 'java packet.Program $1 $2 $3 $4' > programScript
Or, escape them:
echo "java packet.Program \$1 \$2 \$3 \$4" > programScript
Upvotes: 0