0

I want to loop over a directory and pick all files with a given extension (recusively) and echo the file path. Somehow this is not working but for what I have read till now this should work. If I run it in iTerm it works and I see the files but when I run it with make I just get empty echoed lines. The amount of lines is correct I just see no file path.

OS: macOS 10.14.5 Make: GNU Make 3.81

clean:
    for f in log/**/*.log; do \
        echo $f; \
    done

Answers I read:

muuvmuuv
  • 901
  • 2
  • 13
  • 39

1 Answers1

1

There are two mistakes.

First, ** is non-POSIX, but make uses /bin/sh by default. So you have to setup another shell in your makefile, for example, SHELL=/bin/bash

Next, echo $f; \ gets expanded by make before feeding it to the shell. So you must escape it with double dollar: echo $$f; \

Matt
  • 13,674
  • 1
  • 18
  • 27