0

In my Makefile, I would like to assign a value to a variable when a target is executed:

var=`find dir_name -name "file_name"`

How do I do this? It didn't work when I just put the assignment in the target.

tbodt
  • 16,609
  • 6
  • 58
  • 83
Aabha Geed
  • 39
  • 1
  • 11
  • Give us the full target in question please (including the variable usage). Does that target itself use the variable or does a prerequisite use it? – Etan Reisner Apr 09 '15 at 12:36
  • under mytarget I search for a file location using find command. I want to collect the file path in variable var. the target itself uses the variable – Aabha Geed Apr 09 '15 at 12:37
  • So this isn't a make variable then? This is a shell variable? Then your problem is that each line is run in its own shell. If you want to use the variable from one line on another you need to continue the shell line with "\" at the end. See my answer [here](http://stackoverflow.com/a/29500862/258523) for a bit of a discussion about this. – Etan Reisner Apr 09 '15 at 12:40
  • yes it is a shell variable that i am trying to use via make. I already have a \ to continue shell – Aabha Geed Apr 09 '15 at 12:41
  • Then what's the problem. Show us the full rule and tell us **exactly** what isn't working. – Etan Reisner Apr 09 '15 at 12:41
  • Added in the question – Aabha Geed Apr 09 '15 at 12:44
  • That's not the full rule (which I've repeatedly asked for). But it happens to contain enough to tell us the problem. You cannot have spaces around `=` signs in shell assignments. – Etan Reisner Apr 09 '15 at 13:23

0 Answers0