
Bash Startup Files
coding三月 03, 20211mins
OP
ShellH1
- Interactive Shells
/etc/bash.bashrc、~/.bashrc- Login Shells
/etc/profile、~/.bashprofile, ~/.bashlogin, ~/.profile - Non Login Shells
- Login Shells
- Non-interactive Shells
$BASH_ENVWhen Bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute.java
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
Environment VariableH1
理论上,任何 shell 脚本都可以初始化环境变量,但为了维护方便,环境变量的定义集中在几个特定的文件中。对全局变量来说是:/etc/profile, /etc/bash.bashrc 和 /etc/environment. 每个文件都有不同的限制,请根据需要选择要使用的文件。
/etc/profile仅初始化登陆 shell 的环境变量。它可以执行脚本并支持 Bash 兼容 Shell。/etc/bash.bashrc仅初始化交互 shell,它也可以执行脚本但是只支持 Bash。/etc/environment被 PAM-env 模块使用,和登陆与否,交互与否,Bash与否无关,所以无法使用脚本或通配符展开。仅接受variable=value格式。 以将 ~/bin 加入某些特定用户的 PATH 为例,可以将其放入 /etc/profile 或 /etc/bash.bashrc:java
# If user ID is greater than or equal to 1000 & if ~/bin exists and is a directory & if ~/bin is not already in your $PATH# then export ~/bin to your $PATH.if [[ $UID -ge 1000 && -d $HOME/bin && -z $(echo $PATH | grep -o $HOME/bin) ]]thenexport PATH=$HOME/bin:${PATH}fi
参考H1
[2]: https://wiki.archlinux.org/index.php/Environmentvariables(简体中文)
评论
新的评论
上一篇
SameSite Cookie
概念 Secure Cookies 标记为 Secure 的 Cookie 只应通过被 HTTPS 协议加密过的请求发送给服务端 SameSite 限制第三方 Cookie Strict Cookies只会在第一方上下文中发送,不会与第三方网站发起的请求一起发送 Lax C…
下一篇
小程序跨平台
React小程序运行时 原理 小程序的渲染层和逻辑层分别由两个线程管理:渲染层的界面使用 WebView 进行渲染;逻辑层采用 JSCore 运行 JavaScript 代码。一个小程序存在多个界面,所以渲染层存在多个 WebView。这两个线程间的通信经由小程序 Native…
