非交互式登录 shell 的使用示例是什么?

Luk*_*ali 5 ssh bash scripts

我知道这是极其罕见的概念,但想不出它的用途。我确实有一个想法,我们可能想要执行一个包含通过 ssh 登录服务器的命令的脚本,这是有时需要完成的事情,它是非交互式登录 shell 有用的示例吗?

ubf*_*an1 3

研究 Unix 方式命令的运行:现有(登录)shell 被分叉(复制),并执行命令。如果分叉 shell 运行另一个 shell,则该 shell 是非交互式的。输入命令”

$ echo "$-  'i' indicates interactive"
himBHs  'i' indicates interactive
Run Code Online (Sandbox Code Playgroud)

现在将上面的行放入文件(foo)中并运行

bash foo
hB  'i' indicates interactive
Run Code Online (Sandbox Code Playgroud)

没有“i”,因此在非交互式 shell 中运行。使 foo 可执行并重试”

chmod +x foo
./foo
hB  'i' indicates interactive
Run Code Online (Sandbox Code Playgroud)

再次强调,没有“i”,除非你强迫这样做:

bash -i foo
himBH  'i' indicates interactive
Run Code Online (Sandbox Code Playgroud)

然后你又看到了“i”