2016-11-25 92 views
0

在我的Makefile中,我試圖提取virtualbox橋接口IP,我設法讓它存儲命令的輸出並回顯它,但是它包含不需要的字符:「Value :「我只想要IP,我曾嘗試在VBoxManageCommand後添加一個awk管道,但似乎無法使其工作。有任何想法嗎?在Makefile中刪除shell執行結果的子字符串

$(eval VB_IP := "$(shell VBoxManage guestproperty get machinename "/VirtualBox/GuestInfo/Net/2/V4/IP")") 

@echo $(VB_IP) ### This gives: Value: 10.224.199.19 

docker-machine ssh oasis "sed '/--label provider=virtualbox/a --insecure_registry $(VB_IP):5000' /var/lib/boot2docker/profile" ###This makes use of the extracted ip 

回答

1

添加管道命令應該工作:

test: 
    $(eval VB_IP := $(shell echo Value: 10.224.199.19 | cut -f2 -d:)) 
    echo $(VB_IP) 

或者你可以使用$(subst FROM,TO,TEXT)代替脫殼而出的:

$(eval VB_IP := $(subst Value:,,$(shell echo Value: 10.224.199.19))) 
+0

$(EVAL VB_IP1:= 「$(SHELL VBoxManage guestproperty獲得計算機名 」/ VirtualBox虛擬/ GuestInfo /網/ 2/V4/IP「)」); $(eval VB_IP:= $(shell echo $(VB_IP1)| cut -f2 -d :)) ? –

+0

@DavidKarlsson:我使用'echo'是因爲'VBoxManage'在我的機器上沒有返回相同的輸出。 – choroba

1

我們可能要嘗試一些實驗中,我們發現之前一個適合你的解決方案。請注意,內部和外部規則的工作方式不同。試試這個,沒有任何規則內,並告訴我們結果:

VB_IP := $(word 2, $(shell VBoxManage guestproperty get machinename "/VirtualBox/GuestInfo/Net/2/V4/IP")) 
$(info the first result is $(VB_IP)) 

你也可以試試這個規則裏,並告訴我們結果:

somerule: 
    VBoxManage guestproperty get machinename "/VirtualBox/GuestInfo/Net/2/V4/IP" | cut -f2 -d: 
0

謝謝您的幫助,這是什麼最終爲我們工作:

# Update the docker-machine daemon with the insecure_registry from the brigded interface on virtualbox 
$(eval VB_IP_ := "$(shell VBoxManage guestproperty get machinename "/VirtualBox/GuestInfo/Net/2/V4/IP")") 
$(eval VB_IP := $(shell echo $(VB_IP_) | sed 's/[^ ]* //')) 

@echo Adding private docker repo: registry: $(VB_IP) 
docker-machine ssh oasis "sed -i '' '/--label provider=virtualbox/a --insecure_registry $(VB_IP):5000' /var/lib/boot2docker/profile" 
相關問題