我曾尝试在makefile中放入以下命令。在sed命令中使用makefile变量
#get Local Ip Address
LOCALIP=$(shell ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | awk '{print $1}') &
#get Web Url from User
@read -p "Enter Web Url:" weburl; \
sed -e "\|$LOCALIP $weburl|h; \${x;s|$LOCALIP $weburl||;{g;t};a\\" -e "$LOCALIP $weburl" -e "}" hosts.txt
当我尝试执行命令,我有望获得sed命令类似如下:
sed -e "\|192.168.5.1 www.weburl.com|h; \${x;s|192.168.5.1 www.weburl.com||;{g;t};a\\" -e "192.168.5.1 www.weburl.com" -e "}" hosts.txt
不过,我得到以下,
sed -e "\|/s/$/OCALIP eburl|h; \" hosts.txt
Makefile变量通常包含在'$(...)'中。 –
我试过了。现在我得到以下。 sed -e“\ | 192.168.5.1 & |h; \”hosts.txt –
而不是试图将所有这些shell语句转换为Makefile语法,您不能将它们放入脚本并从Makefile调用该脚本吗? – oliv