Bash expect 中星号 * 的转义不一致?

Bash inconsistent escaping of asterisk * in expect?

我有 2 个 expect 命令,但是,我不明白正在进行的扩展。 (在上下文中,我有一个连接到服务器的脚本,下载并清空指定目录中的所有日志文件。)

expect -c "
    set timeout 1
    spawn scp user@hostname:/logdir/\*.log .
    expect yes/no { send yes\n ; exp_continue }
    expect password: { send $pass\n }
    expect 100%
    sleep 1
    exit
";

在此命令中,expect 将生成的命令显示为 spawn scp user@hostname:/logdir/*.log .,这意味着 \ 已被删除。

expect -c "
    set timeout 1
    spawn ssh user@hostname {echo '' | tee /logdir/\*.log > /dev/null}
    expect yes/no { send yes\n ; exp_continue }
    expect password: { send $pass\n }
    expect eof
";

在此命令中,expect 将生成的命令显示为 spawn ssh user@hostname echo '' | tee /logdir/\*.log > /dev/null,这意味着 \ 被删除。为什么不同? (如果我不转义星号,比如 tee /logdir/*.log,它确实有效。但我不明白与上述情况有什么不同?)

这就是 Tcl 处理反斜杠的方式。

[bash] # tclsh
% puts \*
*
% puts "\*"
*
% puts {\*}
\*
%

根据Tcl doc

If a backslash (\) appears within a word then backslash substitution occurs. In all cases but those described below the backslash is dropped and the following character is treated as an ordinary character and included in the word. The following table lists the backslash sequences that are handled specially, along with the value that replaces each sequence.

[...]

Backslash substitution is not performed on words enclosed in braces, except for backslash-newline as described above.