UNIX:完整参考,第二版,Kenneth H. Rosen 等人。
登录后可以使用shell的名称作为命令启动另一个shell;例如,要启动 Korn shell,您可以在命令提示符下键入 ksh。这种类型的 shell 不是登录 shell,您不必再次登录即可使用它,但它仍然是一个交互式 shell,这意味着您通过键入命令与 shell 进行交互(而不是使用 shell 来运行一个脚本,如第 20 章所述)。当您使用图形界面时,在终端窗口中运行的 shell 实例也是交互式非登录 shell。当您启动非登录 shell 时,它不会读取您的 .profile、.bash_profile 或 .login 文件(或您的 .logout 文件),但它仍会读取第二个 shell 配置文件(例如 .bashrc)。这意味着您可以测试对 .
我正在浏览以上几行,但我不明白交互式 shell 的含义。如果我使用终端,.profile 是不是真的没有被读取?
此外,当您说 bourne 不是交互式 shell 而 bash/csh 是交互式 shell 时,这意味着什么?
对于命令(内置或外部),直接在 bash shell 进程中运行它和bash -c
在 bash shell中运行它有什么区别?与彼此相比,它们的优点和缺点是什么?
For example, in a bash shell, run `date` directly, and run `bash -c
date`. Also consider a builtin command instead of an external one.
Run Code Online (Sandbox Code Playgroud) 我在 Windows 10 机器上,启用/配置了适用于 Linux 的 Windows 子系统 (Ubuntu)。为了解释我的问题,让我向您展示两种情况:
场景一:
cmd.exe
提示bash
在cmd.exe
提示符下运行bash
)我运行给定的命令,dwiextract
在我的情况下调用(来自神经影像分析软件包)工作正常,表明软件包安装成功。
场景2:
cmd.exe
提示bash
from cmd.exe
:bash -c dwiextract
我明白了command not found
。
(注意我在bash -c
这里了解到并在其他场合成功使用了它。)
下图准确显示了我所做的:
我的问题:这两种情况不应该是等价的。为什么方案 1 有效而方案 2 无效?
非常感谢。
来自https://unix.stackexchange.com/a/276611/674
当
bash
与 一起运行时-c
,它被认为是一个非交互式 shell~/.bashrc
,除非-i
指定,否则它不会读取。所以,Run Code Online (Sandbox Code Playgroud)$ type cp cp is aliased to ‘cp -i’ # Defined in ~/.bashrc $ cp .file1 file2 cp: overwrite ‘file2’? n $ bash -c "cp .file1 file2" # Existing file is overwritten without confirmation! $ bash -c -i "cp .file1 file2" cp: overwrite ‘file2’? n
shell 是由bash -i -c <command>
交互式还是非交互式创建的?
这样的 shell 不接受来自 stdin 的命令,是吗?所以它不是交互式的,是吗?
这样的 shell 读取~/.bashrc
,所以它不能是非交互式的,对吗?