How to use echo in shell command from Makefile?

14,519

The problem is that the shell is seeing the parentheses in $RELEASE outside of any quotes, so is trying to interpret them. Two things to try: put double-quotes around the reference to $(RELEASE), and use := per this. For example:

SHELL:=/bin/bash.  #at the top of the makefile
IS_FEDORA22_i686 := $(shell echo "$(RELEASE)" | $(EGREP) -i -c "fc22.i686")

Edit: uname output with switches like -m doesn't usually have any shell metacharacters. The same problem could happen with any variable that did. That's why it's useful to set SHELL in your makefile - if the user is running csh, you will have different problems than with bash.

Share:
14,519

Related videos on Youtube

jww
Author by

jww

Updated on September 18, 2022

Comments

  • jww
    jww over 1 year

    I have a GNU makefile. It runs fine on Linux, Solaris and OS X. However, under Cygwin-32, Cygwin-64 and MinGW, it produces:

    /bin/sh: -c: line 0: syntax error near unexpected token `('
    /bin/sh: -c: line 0: `echo 2.0.4(0.287/5/3) | egrep -i -c "fc22.i686"'
    

    There is no Line 0; and the test for Fedora 22 actually occurs Line 73:

    IS_FEDORA22_i686 = $(shell echo $(RELEASE) | $(EGREP) -i -c "fc22.i686")
    

    What is going on with Cygwin and MinGW? More importantly, how can I fix it?


    I know it sounds like a stretch, so here is a screen capture. The upper left is MinGW. The center is Cygwin-32. The lower right is Cygwin-64.

    enter image description here