The expect script should be called like this:
./userspecifiedcmd.exp root "$password" "$server" "$usrcmd"
Always quote your shell variables unless you have a compelling to omit them.
In expect, map the args to variables like this:
lassign $argv user password server usercommand
The lrange
command returns a list, and when you handle a list like a string, you get the {}
artifacts. Be aware of your Tcl data types: handle lists as lists, strings as strings. When you have a list, use join
to "convert" it into a string cleanly.
The Tcl manual pages are helpful: http://tcl.tk/man/tcl8.5/TclCmd/contents.htm
As is the Tcl tutorial: http://tcl.tk/man/tcl8.5/tutorial/tcltutorial.html