mobile wallpaper 1
mobile wallpaper 2
mobile wallpaper 3
mobile wallpaper 4
374 words
1 minute
shell程序
2026-10-16

1. shell#

1.1 概念#

  • shell 程序是一种交互式程序,区别于 shell 脚本。

1.2 shell 的类型#

  • 启动时涉及两种 shell:
    • 默认的交互 shell
      • 用户登录后启动的 shell 程序由 /etc/passwd 中用户记录的最后一个字段指定。
    • 默认的系统 shell
      • 启动时运行 shell 脚本使用,通常是 /bin/sh,作为符号链接指向启动 shell。

2. shell 的父子关系#

2.1 父子 shell#

  • 父子 shell 都是相对的:
    • 父 shell:起始启动的交互式 shell 是一个父 shell。
    • 子 shell:在一个 shell 中输入 bash 命令时,会创建一个新的 shell 程序,被称为子 shell。
  • 使用 exit 命令退出子 shell。

2.2 进程列表#

  • 在一行中指定要依次运行的一系列命令,用 ; 隔开:
    $ pwd ; ls ; cd /etc ; pwd ; cd ; pwd ; ls
  • 在命令列表外加上 (),才形成进程列表,生成一个子 shell 来执行命令:
    $ (pwd ; ls ; cd /etc ; pwd ; cd ; pwd ; ls)

3. 内建命令、外部命令#

3.1 内建命令#

  • 内建命令是 shell 程序自身实现的命令,不需要借助外部程序文件来运行,不会创建子进程。
  • 内建命令的执行速度要更快,效率也更高。
  • 使用 type 命令了解某个命令是否为内建:
    $ type cd
    cd is a shell builtin

3.2 外部命令#

  • 外部命令是存在于 bash shell 之外的程序,不是 shell 的一部分。
  • 执行外部命令时,会创建出一个子进程。
Share

If this article helped you, please share it with others!

shell程序
https://kieas.cn/posts/shell程序/
Author
Kieas
Published at
2026-10-16
License
CC BY-NC-SA 4.0

Some information may be outdated

Table of Contents