How to pass multi-word space-divided string value as separate arguments to the program in expect script? -


suppose have simple expect script (simple.exp):

set command "ls -l somedir" spawn $command interact 

executing script results in error because expect treats ls -l (whole string spaces) command rather ls command , -l option:

expect -f simple.exp spawn ls -l couldn't execute "ls -l somedir": no such file or directory      while executing "spawn $command"      (file "simple.exp" line 2) 

what want behaviour similar bash processes string first , breaks down distinct arguments start command:

bash -c "ls -l somedir" 

note variable command hardcoded in script simplicity. in real script supplied argument (arbitrary command line string).

the safest way make command use tcl's list command. example:

#!/usr/bin/expect set cmd [list ls -l "a b c.txt"] if { [package vcompare $tcl_version 8.5] < 0 } {     eval spawn -noecho $cmd } else {     spawn -noecho {*}$cmd } expect eof 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -