0

I have this line of bash script, which I'm trying to add to a makefile:

 go_files=$(find . -name "*.go" -not -path "*/test1/*" -not -path "*/test2/*")

I've already tried these: (due to this stackoverflow answer)

for_on_go:
    $(eval p := $(find . -name "*.go" -not -path "*/test1/*" -not -path "*/test2/*"))
    @echo $(p)

and

for_on_go:
    protos=$(find . -name "*.go" -not -path "*/test1/*" -not -path "*/test2/*"); \
    echo $$protos; \

which both are not working or echoing the correct result. I also want to loop over these results after this.

umläute
  • 28,885
  • 9
  • 68
  • 122
no746
  • 408
  • 6
  • 23
  • Each line in a makefile recipe executes in its own sub-shell. So if you succeed in assigning a value to a *shell* variable, that variable will not survive to the next line in the recipe. You can assign a value to a *Make* variable, but that will not be specific to a rule. What do you actually want to do? – Beta Feb 16 '20 at 14:22
  • There are many issues with what you're trying to do as Beta points out. However, the basic fundamental problem you have is that `$` is a special character in makefiles. So if you want to use the literal `$` in your recipes you need to escape it, using `$$` instead. So to use shell command replacement like `$(find ...)` you have to write it as `$$(find ...)`. Or else go back to the traditional syntax with backquotes: `\`find ...\`` – MadScientist Feb 16 '20 at 17:27

1 Answers1

0

if you don't have to run find within a rule, you can just do it like so (using $(shell...) for running a command, and $(...) for multi-characters variables

protos=$(shell find . -name "*.go" -not -path "*/test1/*" -not -path "*/test2/*")

for_on_go:
    echo $(protos)
umläute
  • 28,885
  • 9
  • 68
  • 122