0

In bash, I can do this:

for name in sqls/*.{schema,migration}.sql; do
    echo $name; # some operation on the file name
done

It would output something like this:

sqls/0001.schema.sql
sqls/0002.schema.sql
sqls/0003.migration.sql
sqls/0004.schema.sql
sqls/0006.schema.sql
sqls/0007.schema.sql

However, if I put the same loop into a Makefile:

names:
    for name in sqls/*.{schema,migration}.sql; do echo $name; done

The output become:

sqls/*.{schema,migration}.sql

How can I do the same thing in a Makefile?

  • 3
    Could you edit your question to show exactly what you tried in your Makefile? – Stephen Kitt Feb 23 '17 at 9:38
2

You need to realize that the {...} is a bash construct whilst Makefiles generally launch the sh which does not support the brace expansion feature.

However all's not lost; if you are with GNU Make then you can tell Make to use bash by putting this little line SHELL := bash at the very top of your Makefile.

0

What you want is :

names:
    for name in sqls/*.{schema,migration}.sql; do\
        echo $${name};\ # some operation on the file name
    done

As explained in the docs, that's the difference between accessing GNUMake and bash variables :

LIST = one two three
all:
        for i in $(LIST); do \
            echo $$i; \
        done

Here i is a bash variable, whilst LIST is a GNUMake variable.

In short, if you want bash to recieve a dollar sign $, put a double dollar sign $$ in your makefile. The use of {} or () is equivalent in makefiles or bash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.