Bash here文档与expect不起作用

Bash here文档与expect不起作用,bash,expect,Bash,Expect,我在expect文件中编写了一些代码: #!./expect -f set timeout -1 spawn /path/to/command --foo param1 --bar param2 --password expect "Password for baz which is prompted on the console.: " send "pass\r" expect "> " send "print\r" expect "> " s

我在expect文件中编写了一些代码:

  #!./expect -f

  set timeout -1
  spawn /path/to/command --foo param1 --bar param2 --password
  expect "Password for baz which is prompted on the console.: "
  send "pass\r"
  expect "> "
  send "print\r"
  expect "> "
  send -- "\r"
当我运行它时,输出是:

spawn /path/to/command --foo param1  --bar param2 --password
Password for baz which is prompted on the console.: 
> print

{"stuff"}

> 
> 
我在bash的here文档中有一些代码:

variable=$(/usr/bin/expect <<HEREKALpxT5KZu
  set timeout -1
  spawn /path/to/command --foo param1 --bar param2 --password
  expect "Password for baz which is prompted on the console.: "
  send "pass\r"
  expect "> "
  send "print\r"
  expect "> "
  send -- "\r"
HEREKALpxT5KZu
)

没有第二个“>”和{“东西”}。就像打印命令从未发送过一样。另外,当我在末尾添加“interact”时,它只适用于expect文件,而不适用于here文档。

使用
expect-d
启用调试。可能您的实际expect脚本正文需要保护,以防shell参数扩展:try
variable=$(expect
spawn /path/to/command --foo param1 --bar param2 --password
Password for baz which is prompted on the console.: 
>