So I'm trying to capture the IP address of a Parallels VM guest (Win8) from the host (OS X). I thought a bash script would be good for this. The ultimate goal is to have a single command that will fetch the IP address and then initiate an ssh port redirect.

I am aware of the prlctl enter command, and I do not believe it supports port redirection.

My script thus far:


VM="Win8 Dev"
CMD="prlctl exec \"$VM\" ipconfig | grep "IPv4" | grep -m1 -o '\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}'"
echo $CMD
echo $IP


prlctl exec "Win8 Dev" ipconfig | grep IPv4 | grep -m1 -o
'\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}' Failed to get VM config:
The virtual machine could not be found. The virtual machine is not
registered in the virtual machine directory on your Mac. Contact the
Parallels support team for assistance.

So it appears that the CMD variable is being populated correctly, but something is getting lost when trying to assign the output of the command to the IP variable.

Any thoughts on what I am doing wrong?

  • If you run prlctl exec "Win8 Dev" ipconfig directly in the shell, does it work correctly? Same for the whole content of $CMD.
    – nohillside
    Oct 28, 2014 at 5:37
  • i think it would work if you use eval or just the command as is instead of echo in your last line. cause echo simply prints what is in the Variable and does not interpret it.
    – konqui
    Oct 28, 2014 at 6:15
  • @konqui: the second to last line should interpret the $CMD variable. IP=$($CMD)
    – Sam Axe
    Oct 29, 2014 at 6:50
  • sorry my fault some how have overseen this line.
    – konqui
    Oct 29, 2014 at 7:00

1 Answer 1


If anyone else needs to do this, here is the solution I came up with:


VM="name of my VM"
CMD="prlctl exec \"$VM\" ipconfig | grep "IPv4" | grep -m1 -o '\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}'"
IP=$(eval $CMD)

#once you have the correct data in the $IP variable you can do something with it.. I initiate an ssh session, but you can do whatever you like.

I have no idea why eval is needed here. Someone more familiar with bash will be needed to answer that mystery.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .