0

This code doesn't work:

$ cat Makefile
dev:
        AWS_PROFILE=foobar-$@ echo $$AWS_PROFILE

demo:
        AWS_PROFILE=foobar-$@ echo $$AWS_PROFILE

Based on my target, I want the AWS_PROFILE correctly setup for the commands in the target. How does one achieve this with GNU Make 4.2.1?

hendry
  • 9,725
  • 18
  • 81
  • 139

1 Answers1

0

Add a semi-colon before the echo command:

dev:
    AWS_PROFILE=foobar-$@; echo $$AWS_PROFILE

Each line of a recipe is sent to a different shell. So, if you want to propagate shell variables you must define and use them on the same line, in the same shell list. You could also use && or || to join your individual shell commands.

Note that, for better readability, you can use the line continuation:

dev:
    AWS_PROFILE=foobar-$@; \
    echo $$AWS_PROFILE
Renaud Pacalet
  • 25,260
  • 3
  • 34
  • 51