When you call the function with this parameter:
Code:
"'[NFS2] lab-vcenter/lab-vcenter.vmx'"
The single quote marks, being escaped by the double-quotes, become
literal, and are stored in the variable along with the rest of the string. These are then
NOT re-parsed later (generally) as shell syntax. So when you launch the command like this...
Code:
/usr/bin/vmware-cmd -H $1 -U root -P 'pass!word' $2 gettoolslastactive
...the $2 string is passed to the vmware-command as including those literal quote marks.
The echoed command may look the same by eyeball, but to the shell they are completely different, due to the line parsing order. Quotes are processed before variable expansion, so the shell never has a chance to parse the ones stored in the variable.
In addition, since you didn't quote the $2 parameter, the space
is processed and the contents are word-split, because word splitting happens
after parameter expansion.
So you're actually passing the following two literal strings to vmware-cmd:
Code:
'[NFS2]
lab-vcenter/lab-vcenter.vmx'
It will likely start working if you remove the extra set of quotes from the passed parameter, and double-quote the "$2".
BTW, it's a good idea to train yourself to
always quote your variables, parameters, and other expansions, unless and until you actually need word-splitting to occur.
See here for more on how the shell parses arguments:
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes
This link goes into more detail about how it's generally not advisable to try storing shell commands/syntax inside variables:
http://mywiki.wooledge.org/BashFAQ/050