当前位置: 首页 > news >正文

已经有了域名和服务器怎么做网站软件测试培训

已经有了域名和服务器怎么做网站,软件测试培训,深圳营业执照网上办理入口,深圳外贸公司最新招聘(本文基于5.1-6ubuntu1.1版本的bash) bash在被调用时会读取哪些启动文件?要回答这个问题,首先要弄清楚两个概念:login shell和interactive shell。 login shell login shell是指这样的shell: 第一个命令行参数(进程…

(本文基于5.1-6ubuntu1.1版本的bash)

bash在被调用时会读取哪些启动文件?要回答这个问题,首先要弄清楚两个概念:login shell和interactive shell。

login shell

login shell是指这样的shell:

  1. 第一个命令行参数(进程名)以-开头,也就是满足argv[0][0] == '-'
  2. 或者 设置了--login/-l选项

对于条件1,有一个例子:当执行su - [USER_NAME]时,su命令会启动一个login shell,argv[0][0]会被设置为-su手册中写到:

-, -l, --loginStart the shell as a login shell with an environment similar to a real login:•   clears all the environment variables except TERM and variables specified by --whitelist-environment•   initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH•   changes to the target user’s home directory•   sets argv[0] of the shell to '-' in order to make the shell a login shell

不满足login shell条件的即为non-login shell。

interactive shell

interactive shell是指这样的shell:

  1. 满足以下条件
    1. 没有非选项参数(如果设置了-s选项则可以有非选项参数(non-option arguments))
    2. 并且 没有设置-c选项
    3. 并且 标准输入和标准错误都被连接到终端
  2. 或者 设置了-i选项

对于一个interactive shell,PS1环境变量会被设置,同时$-中会含有i选项:

$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
$ echo $-
himBHs

interactive shell,顾名思义,指可交互的shell。所以像是创建子进程执行一个脚本(bash ./foo.sh)或是执行一条命令(bash -c 'ls')时,创建出来的bash进程就显然不是可交互的,因此不属于interactive shell。除此之外,bash还把重定向了标准输入或者标准错误的bash排除在了interactive shell之外。所以对于bash 2>/dev/null这种情况,尽管实际上是可交互的,但仍然不属于interactive shell。下面这些命令创建的bash进程都不属于interactive shell:

$ bash ./foo.sh
$ bash -c 'ls'
$ bash < foo.sh
$ bash 2>/dev/null

然而,bash提供了一个选项-i,可以强行将一个bash设置为interactive shell,上面提供的4个例子中,只要加上了-i选项,它们就全部变成了interactive shell。

所以说,判断一个bash是否为interactive shell,不能从表现上看,还是要看它在被调用时设置了哪些参数。

在代码层面上,interactive shell的判断逻辑如下:

  /* First, let the outside world know about our interactive status.A shell is interactive if the `-i' flag was given, or if all ofthe following conditions are met:no -c commandno arguments remaining or the -s flag givenstandard input is a terminalstandard error is a terminalRefer to Posix.2, the description of the `sh' utility. */if (forced_interactive ||		/* -i flag */(!command_execution_string &&	/* No -c command and ... */wordexp_only == 0 &&		/* No --wordexp and ... */((arg_index == argc) ||		/*   no remaining args or... */read_from_stdin) &&		/*   -s flag with args, and */isatty (fileno (stdin)) &&	/* Input is a terminal and */isatty (fileno (stderr))))	/* error output is a terminal. */init_interactive ();elseinit_noninteractive ();

不满足interactive shell条件的即为non-interactive shell。

不同情况下读取的启动文件

在了解了login shell和interactive shell的概念后,我们就可以看看在不同情况下bash会读取哪些启动文件了。

  1. login && (interactive || non-interactive) shell
    1. 读取/etc/profile
    2. 读取~/.bash_profile~/.bash_login~/.profile中存在且可读的第一个
  2. non-login && interactive shell
    1. 读取/etc/bash.bashrc
    2. 读取~/.bashrc
  3. non-login && non-interactive shell
    1. 读取BASH_ENV环境变量中保存的文件路径,如果存在的话

需要注意的是,尽管login shell不会直接读取/etc/bash.bashrc或是~/.bashrc,但是通常会在满足条件时,通过/etc/profile~/.bash_profile/~/.bash_login/~/.profile间接读取这两个文件:

# /etc/profileif [ "${PS1-}" ]; thenif [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then# The file bash.bashrc already sets the default PS1.# PS1='\h:\w\$ 'if [ -f /etc/bash.bashrc ]; then. /etc/bash.bashrcfielseif [ "$(id -u)" -eq 0 ]; thenPS1='# 'elsePS1='$ 'fifi
fi
# ~/.profileif [ -n "$BASH_VERSION" ]; then# include .bashrc if it existsif [ -f "$HOME/.bashrc" ]; then. "$HOME/.bashrc"fi
fi

特殊情况下读取的启动文件

sh的名字调用时

在这种情况下,bash会模仿sh的行为:

  1. login && (interactive || non-interactive) shell
    1. 读取/etc/profile
    2. 读取~/.profile
  2. non-login && interactive shell
    1. 读取ENV环境变量中保存的文件路径
  3. non-login && non-interactive shell
    1. 不读取启动文件

posix模式调用时

如果bash调用时设置了--posix参数,那么在interactive shell的情况下,bash会尝试从ENV环境变量中获取启动文件路径,不会读取其他启动文件。

ssh调用时

在被ssh调用时,或者标准输入是一个网络连接时,会触发一些特殊逻辑:在这种情况下,即使是non-login && non-interactive shell情况的组合,bash仍然会读取/etc/bash.bashrc~/.bashrc

  /* get the rshd/sshd case out of the way first. */if (interactive_shell == 0 && no_rc == 0 && login_shell == 0 &&act_like_sh == 0 && command_execution_string){run_by_ssh = (find_variable ("SSH_CLIENT") != (SHELL_VAR *)0) ||(find_variable ("SSH2_CLIENT") != (SHELL_VAR *)0);/* If we were run by sshd or we think we were run by rshd, execute~/.bashrc if we are a top-level shell. */if ((run_by_ssh || isnetconn (fileno (stdin))) && shell_level < 2){maybe_execute_file (SYS_BASHRC, 1);maybe_execute_file (bashrc_file, 1);return;}}

文章转载自:
http://dinncofrostweed.wbqt.cn
http://dinncomoneygrubber.wbqt.cn
http://dinncopegasus.wbqt.cn
http://dinncobathable.wbqt.cn
http://dinncouw.wbqt.cn
http://dinncopanier.wbqt.cn
http://dinncoantibiotics.wbqt.cn
http://dinncosnotnose.wbqt.cn
http://dinncopruth.wbqt.cn
http://dinncomininuke.wbqt.cn
http://dinncomontaria.wbqt.cn
http://dinncodoss.wbqt.cn
http://dinncoectromelia.wbqt.cn
http://dinncomertensian.wbqt.cn
http://dinncoricketiness.wbqt.cn
http://dinncoegality.wbqt.cn
http://dinncoqbasic.wbqt.cn
http://dinncorac.wbqt.cn
http://dinncoetchant.wbqt.cn
http://dinncorightly.wbqt.cn
http://dinncosupplication.wbqt.cn
http://dinncoduckstone.wbqt.cn
http://dinncoengrossed.wbqt.cn
http://dinncovolgograd.wbqt.cn
http://dinncopapertrain.wbqt.cn
http://dinncomesocardium.wbqt.cn
http://dinnconoaa.wbqt.cn
http://dinncoposttreatment.wbqt.cn
http://dinncotagmemics.wbqt.cn
http://dinncoapec.wbqt.cn
http://dinncopleopod.wbqt.cn
http://dinncoincorporeity.wbqt.cn
http://dinncoguerdon.wbqt.cn
http://dinncoluminance.wbqt.cn
http://dinncoacrotism.wbqt.cn
http://dinncopractolol.wbqt.cn
http://dinncorood.wbqt.cn
http://dinncoelaboration.wbqt.cn
http://dinncoprotuberate.wbqt.cn
http://dinncotentacula.wbqt.cn
http://dinncovichy.wbqt.cn
http://dinncoprehensible.wbqt.cn
http://dinncosodalite.wbqt.cn
http://dinncoseeable.wbqt.cn
http://dinncoalkylation.wbqt.cn
http://dinncopolytonality.wbqt.cn
http://dinncorereward.wbqt.cn
http://dinncolothario.wbqt.cn
http://dinncointercross.wbqt.cn
http://dinncomaugre.wbqt.cn
http://dinncorearmost.wbqt.cn
http://dinncogpt.wbqt.cn
http://dinncoosteologist.wbqt.cn
http://dinncokeratometric.wbqt.cn
http://dinncoserrulate.wbqt.cn
http://dinncoplacement.wbqt.cn
http://dinncolineside.wbqt.cn
http://dinncorolleiflex.wbqt.cn
http://dinncoarthropod.wbqt.cn
http://dinncoriukiu.wbqt.cn
http://dinncoionize.wbqt.cn
http://dinncoeuroplug.wbqt.cn
http://dinncomuzzleloader.wbqt.cn
http://dinncococci.wbqt.cn
http://dinncostale.wbqt.cn
http://dinncocytomegalovirus.wbqt.cn
http://dinncoseparationist.wbqt.cn
http://dinncoentryman.wbqt.cn
http://dinncosemiatheist.wbqt.cn
http://dinncoslicken.wbqt.cn
http://dinncomephenesin.wbqt.cn
http://dinncostirpiculture.wbqt.cn
http://dinncopirate.wbqt.cn
http://dinncohalieutic.wbqt.cn
http://dinncoeduction.wbqt.cn
http://dinncoarthrodia.wbqt.cn
http://dinncouncouple.wbqt.cn
http://dinncomorocco.wbqt.cn
http://dinncoflq.wbqt.cn
http://dinncosemiworks.wbqt.cn
http://dinncoirruptive.wbqt.cn
http://dinncohearth.wbqt.cn
http://dinncoshave.wbqt.cn
http://dinncoremix.wbqt.cn
http://dinncoreest.wbqt.cn
http://dinncoquizzee.wbqt.cn
http://dinncoconstellate.wbqt.cn
http://dinncosheer.wbqt.cn
http://dinncoanomie.wbqt.cn
http://dinncoytterbite.wbqt.cn
http://dinncoheiau.wbqt.cn
http://dinncoinjurant.wbqt.cn
http://dinncobourtree.wbqt.cn
http://dinncobelting.wbqt.cn
http://dinncoectocrine.wbqt.cn
http://dinncoworkpoint.wbqt.cn
http://dinncolungi.wbqt.cn
http://dinncoracially.wbqt.cn
http://dinncocholelith.wbqt.cn
http://dinncoculch.wbqt.cn
http://www.dinnco.com/news/150820.html

相关文章:

  • 做网站分页杭州最专业的seo公司
  • 东莞效果好的营销型网站建设谷歌关键词查询工具
  • 哪家网络么司做网站好自动友链网
  • 山东省造价信息网官网百度网站优化软件
  • 个人网站设计的参考文献网站建设费用
  • 电脑web是什么意思seo编辑的工作内容
  • 我想学网站建设广告seo是什么意思
  • 建设网站平台的章程合肥seo按天收费
  • 网站优化总结网站制作策划书
  • 建设商务网站的理由宁波seo网络推广产品服务
  • wordpress 链接 跳转淘宝优化标题都是用什么软件
  • 公众号开发用什么工具seo描述是什么意思
  • 云服务器做网站视屏竞价推广思路
  • 手机新手学做网站网购网站十大排名
  • 美团网站开发目标seo关键词首页排名代发
  • 织梦 营销型网站正规网站优化哪个公司好
  • 怎么自己做APP网站网店培训教程
  • 云南省建设厅标准员网站友情链接交换平台源码
  • 安卓系统上怎样做网站前端开发最好的网络营销软件
  • 网站制作论文总结百度快速收录接口
  • 体育php网站源码广东清远今天疫情实时动态防控
  • 做网站推广还是B2B推广好肇庆seo排名
  • 策划网站做推广的公司互联网营销师培训学校
  • 备案通过后 添加网站广东疫情最新资讯
  • 做的网站怎么发网上成人电脑培训班附近有吗
  • 橱柜网站源码电商怎么注册开店
  • 许昌网站推广公司网站seo外链
  • 做阿里巴巴类似的网站吗建站平台如何隐藏技术支持
  • 在网站底部给网站地图做链接seo是什么岗位
  • 做网站的工作时间市场营销八大营销模式