expect
is a TCL interpreter, ${cmd// /_}
is a Korn shell parameter expansion operator. TCL is not ksh, or any shell for that matters.
After reading the expect
man page, your next step should be to study the TCL documentation. See for instance https://tcl.tk/doc/ though you can also install the man pages on your system for your version of TCL (you may need to install a tcl-doc
package).
Here to do character substitutions, you can use TCL's string map
for instance:
set cmd "abc def ghi lkj"
set log [string map {" " _} $cmd]
puts $log
Or consider that $cmd
as a list and join with _
:
set cmd "abc def ghi lkj"
set log [join $cmd _]
puts $log
Which would output abc_def_ghi_lkj
.
If you want ghi_lkj
, then, that's not only SPC to _
you want to do.
Possibly you want the last two words joined with _
or all but the first 2 joined with _
:
set cmd "abc def ghi lkj"
set log [join [lrange $cmd 2 end] _]
puts $log