Put command result in variable within makefile target

Tomáš Zato - Reinstate Monica

I am trying to install something in tomcat webapp. This is beginning of my install target:

tomcat=`locate --regex "^(/var/lib/tomcat[0-9]{1,2}/webapps/[^/]+/)AppName\.html$" -l 1 | tr -d "\n"`
echo "Tomcat: $tomcat"
# If the string is empty (no path matched) or the path does not exists (that should never really happen)
# terminate
if [ -z "$tomcat" ] || [ ! -f "$tomcat" ]; then 
  echo "Application not found on filesystem."
  exit 404
fi

However this is the output:

tomcat=`locate --regex "^(/var/lib/tomcat[0-9]{1,2}/webapps/[^/]+/)AppName\.html -l 1 | tr -d "\n"`
/bin/sh: 1: Syntax error: Unterminated quoted string
makefile:77: recipe for target 'install' failed
make: *** [install] Error 2

Everyone else claims that you can use ` (backtick) to assign command stdout output into variable. I even used tr -d "\n" to delete all newline characters, may they appear. And the code works flawlessly in shell:

XXXXX@debianvirtualbox:~$ tomcat=`locate --regex "^(/var/lib/tomcat[0-9]{1,2}/webapps/[^/]+/)AppName\.html$" -l 1 | tr -d "\n"`
XXXXX@debianvirtualbox:~$ echo $tomcat
/var/lib/tomcat8/webapps/websight/AppName.html

What else is there to fix?

klimpergeist

$ signs are notorious in makefiles for causing trouble because they are interpreted as variable markers. Here just doubling the one in the first line should do the trick:

AppName\.html$$"

Also have a look at other posts to learn more about makefile escaping issues.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

GNU Make - Set MAKEFILE variable from shell command output within a rule/target

From Dev

Setting Makefile variable to result of command in rule

From Dev

How to put this command in a Makefile?

From Dev

Makefile set variable in target

From Dev

Run a command in GNU and BSD Makefile and store the result into a variable

From Dev

Run a command in GNU and BSD Makefile and store the result into a variable

From Dev

Target dependencies from variable in Makefile

From Dev

Generate Target in Makefile from a variable

From Dev

Using a result of shell's find as a target in a Makefile

From Dev

Put a variable in this PHP Command

From Dev

Execute command within variable

From Dev

Make command using default target name 'Makefile'

From Dev

Assigning variables inside a command inside a Makefile target

From Dev

How to pass target stem to a shell command in Makefile

From Dev

Assign result of command in a variable

From Dev

Store the result of a command in a variable

From Dev

makefile: fail on single make target if variable empty

From Dev

Put the result of simple tag into a variable

From Dev

Return the result or put it in a variable first?

From Dev

How to put result of query in a variable?

From Dev

Return the result or put it in a variable first?

From Dev

How to put result of query in a variable?

From Dev

Put select result in a ksh variable

From Dev

Import multiple libraries in makefile within Javac command

From Dev

How to force parameter expansion of $ variable within result of `grep` to pass to another command

From Dev

How to force parameter expansion of $ variable within result of `grep` to pass to another command

From Dev

How do you conditionally call a target based on a target variable (Makefile)?

From Dev

Makefile variable referencing within a nested loop

From Dev

`cd` does not actually go into directory within a Makefile target

Related Related

  1. 1

    GNU Make - Set MAKEFILE variable from shell command output within a rule/target

  2. 2

    Setting Makefile variable to result of command in rule

  3. 3

    How to put this command in a Makefile?

  4. 4

    Makefile set variable in target

  5. 5

    Run a command in GNU and BSD Makefile and store the result into a variable

  6. 6

    Run a command in GNU and BSD Makefile and store the result into a variable

  7. 7

    Target dependencies from variable in Makefile

  8. 8

    Generate Target in Makefile from a variable

  9. 9

    Using a result of shell's find as a target in a Makefile

  10. 10

    Put a variable in this PHP Command

  11. 11

    Execute command within variable

  12. 12

    Make command using default target name 'Makefile'

  13. 13

    Assigning variables inside a command inside a Makefile target

  14. 14

    How to pass target stem to a shell command in Makefile

  15. 15

    Assign result of command in a variable

  16. 16

    Store the result of a command in a variable

  17. 17

    makefile: fail on single make target if variable empty

  18. 18

    Put the result of simple tag into a variable

  19. 19

    Return the result or put it in a variable first?

  20. 20

    How to put result of query in a variable?

  21. 21

    Return the result or put it in a variable first?

  22. 22

    How to put result of query in a variable?

  23. 23

    Put select result in a ksh variable

  24. 24

    Import multiple libraries in makefile within Javac command

  25. 25

    How to force parameter expansion of $ variable within result of `grep` to pass to another command

  26. 26

    How to force parameter expansion of $ variable within result of `grep` to pass to another command

  27. 27

    How do you conditionally call a target based on a target variable (Makefile)?

  28. 28

    Makefile variable referencing within a nested loop

  29. 29

    `cd` does not actually go into directory within a Makefile target

HotTag

Archive