Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run sub Shell script in Makefile?

Tags:

bash

makefile

I want to execute a Shell command but I didn't know how to do a sub bash command correctly in my Makefile

import-bd:
    @while ! nc -z $(make ips | awk '/mysql/ { print $2 }') 3306; do \
        sleep 1 \
    done
    ...

Thanks for your help !

like image 672
Nicolas S. Avatar asked May 17 '18 11:05

Nicolas S.


1 Answers

You need to quote the $s and add a ;

import-bd:
    @while ! nc -z $$(make ips | awk '/mysql/ { print $$2 }') 3306; do \
        sleep 1; \
    done

When make sees a single $, it tries to do a variable expansion. By writing $$, make passes a single $ to awk (or, more precisely, it passes a single $ to SHELL which invokes awk). Also, the semi-colon after sleep 1 is needed because make strips the newline.

like image 155
William Pursell Avatar answered Oct 14 '22 19:10

William Pursell