0

Referring documentation, wrote below target specific variable LOGIN_COMMAND.

Idea is to assign this variable only when user runs make target1


In the below Makefile:

target1 : LOGIN_COMMAND := $(shell aws ecr get-login --no-include-email | sed 's|https://||')

target1:
    $(shell LOGIN_COMMAND)
    $(shell ls)

make target1 is giving below error:

make: LOGIN_COMMAND: Command not found

How to resolve this error?

tripleee
  • 175,061
  • 34
  • 275
  • 318
overexchange
  • 15,768
  • 30
  • 152
  • 347

2 Answers2

3

I can't understand why everyone is always using $(shell ...) inside recipes. Is there some kind of broken howto somewhere that recommends this? It's so ubiquitous and I've never seen any example makefiles that do it (rightly so, because it's really not a good idea).

Anyway. When you add $(shell LOGIN_COMMAND) what does that do? It starts a shell and tells the shell to run the string LOGIN_COMMAND. That's not a command the shell knows, so it gives you the error "command not found". Try typing the string LOGIN_COMMAND at your shell prompt: it's the same thing.

Presumably you meant the contents of the variable LOGIN_COMMAND. For that you need to write it as $(LOGIN_COMMAND) so make knows it's a variable reference not a string.

But using $(shell ...) in a recipe is redundant and confusing because a recipe IS a shell script already.

Plus it's not at all clear what you really want to do. Are you trying to run the ls command on the local system? Or are you trying to run it in on some remote system somewhere?

What do you want to do with the output of the aws ecr get-login ... | sed ... operation?

Before trying to write a makefile, be sure that you can perform the operations you want to do at your shell prompt.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
1

Based on your comment one possible solution is the next:

target1:
      aws ecr get-login --no-include-email | sed 's|https://||' | sh

Note the trailing sh.

Another solution is creating a temporary file and run it:

AWSSH=output.sh
${AWSSH}:
    aws ecr get-login --no-include-email | sed 's|https://||' > $@
    chmod +x $@

target1: ${AWSSH}
    ./${AWSSH}
    rm -f ${AWSSH}
uzsolt
  • 5,832
  • 2
  • 20
  • 32