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 !
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.
You are missing semicolon after sleep 1
.
Also make parses this line first then bash. You need to escape dollar with two dollars.
import-bd:
@while ! nc -z $$(make ips | awk '/mysql/ { print $$2 }') 3306; do \
sleep 1; \
done
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.