为什么`ssh user@server mycommand`会创建一个交互式shell?

Tim*_*Tim 0 bash ssh

$ ssh t@localhost [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
Interactive
Run Code Online (Sandbox Code Playgroud)

我想知道为什么上面的 shell 是交互式的,因为它有非选项参数,并且没有-sor-c-i

从 bash 手册:

交互式 shell 是一个没有非选项参数启动的,除非指定了 -s,没有指定 -c 选项,并且其输入和错误输出都连接到终端(由 isatty(3) 确定),或者一个以-i 选项。

谢谢。

Dop*_*oti 5

您没有执行您认为的测试。您的扩展$-正在发生之前ssh执行命令。展示:

$ set -x
$ ssh home echo $-
+ ssh home echo himxBHs
himxBHs
$ ssh home 'echo $-'
+ ssh home 'echo $-'
hBc
Run Code Online (Sandbox Code Playgroud)