3

命令的执行环境

 3 years ago
source link: https://www.lujun9972.win/blog/2018/10/05/%E5%91%BD%E4%BB%A4%E7%9A%84%E6%89%A7%E8%A1%8C%E7%8E%AF%E5%A2%83/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

命令的执行环境

shell 脚本的执行环境包括如下内容

  • 打开的文件句柄,可能继承于父shell,或者被 exec 重定向操作所修改
  • 当前的工作目录,可能继承于父shell,或者被 cd, pushd, 和 popd 命令所修改
  • 创建文件的mode mask,可能继承于父shell或者被 umask 命令所修改
  • 被trap所设置的信号处理
  • shell参数,可能被变量赋值操作所修改,或者被 set 命令所设置,如果是环境变量则可能由父shell继承
  • 定义的shell函数,可能在执行期间动态定义,也可能继承自父shell(需要通过export标注)
  • 开启/关闭的shell选项,可以在调用shell时设置,也可以为 set 和 shopt 设置. 若bash处于POSIX shell模式下,则子shell会继承父shell的 -e 选项,
  • shell别名,可以被 alias 定义
  • 各种前台和后台job

而当某个外部命令被shell调用时,该外部命令会从shell中继承以下内容:

  • shell所打开的文件句柄, 包括被重定向操作所修改的句柄. 若调用命令时后面加上了&, 而bash没有开启job control的情况下,命令的stdin会被重定向到 /dev/null
  • 当前的工作目录
  • 创建文件时的mode mask

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK