3
# test.mk
test:
    echo a b c | awk '{print $2}'

results in the following: (on both ubuntu and osx)

$ make -f test.mk 
echo a b c | awk '{print }'
a b c

instead of:

$ make -f test.mk 
echo a b c | awk '{print $2}'
b

have tried several combinations of ' and " but can't get figure out how to get make to print $2 literally and awk to substitute the second column

I have these two workarounds:

# test.mk with workaround #1
test:
    test.sh

# test.sh
echo a b c | awk '{print $2}'

...and...

# test.mk with workaround #2
test:
    echo a b c | cut -f2 -d" "

but I'm curious to find out if there is a way to put awk straight into the .mk file

Note: if you are pasting any of these .mk examples, you will probably have to turn the space indents back into tabs.

Alex028502
  • 3,486
  • 2
  • 23
  • 50

1 Answers1

1

Why does AWK not work correctly in a makefile? contains the answer

I didn't come across it when I was looking for an answer initially, but I spotted it in the 'Related' section after I posted. For anybody who is curious:

# test.mk
test:
    echo a b c | awk '{print $$2}'

$ make -f test.mk 
echo a b c | awk '{print $2}'
b
Community
  • 1
  • 1
Alex028502
  • 3,486
  • 2
  • 23
  • 50