tl; dr Adicione -ex
flag.
A questão aqui é que expect
torna mais fácil passar argumentos complexos para alguns comandos ( expect
/ interact
):
The commands that accepted arguments braced into a single list (the expect variants and interact) use a heuristic to decide if the list is actually one argument or many. The heuristic can fail only in the case when the list actually does represent a single argument which has multiple embedded \n's with non-whitespace characters between them. This seems sufficiently improbable, however the argument "-nobrace" can be used to force a single argument to be handled as a single argument. This could conceivably be used with machine-generated Expect code. Similarly, -brace forces a single argument to be handle as multiple patterns/actions.
(from description of expect command) If the arguments to the entire expect statement require more than one line, all the arguments may be "braced" into one so as to avoid terminating each line with a backslash. In this one case, the usual Tcl substitutions will occur despite the braces.
Deixe-me dar um exemplo aqui:
#!/usr/bin/env bash
set -eu
f() {
echo line 1
sleep 1
echo line 2
}
export -f f
echo '
spawn bash -c f
expect {
{line 1} {puts 1}
{line 2} {puts 2}
}
expect \
{line 1} {puts 1} \
{line 2} {puts 2}
' | expect
Saída:
spawn bash -c f
line 1
1
line 2
2
No repositório que encontrei, o heurística no commit mais recente (maio de 2014) é da seguinte forma : se um argumento for passado e houver uma nova linha antes do primeiro não-espaço em branco, o argumento será considerado como múltiplos argumentos em um.