yihong0618 和朋友们的频道 头像

消息来源频道

yihong0618 和朋友们的频道

@hyi0618

频道8,612 位成员公开可见0 人在线

yihong0618 和朋友们的频道

成员规模8,612 位成员
在线情况0 人在线
消息总数10,129 条消息
浏览量总数3,286,989 次浏览

在这个频道里搜索消息……

t.me/hyi0618

TIL:
Link: https://github.com/thoughtbot/til/blob/main/bash/bash_profile_vs_bashrc.md
📌 .bash_profile vs .bashrc
bash(1) can be started in interactive mode or non-interactive mode. It can
also act as a login shell or a non-login shell.
bash(1) is started in interactive mode by your terminal emulator and can also
be started in interactive mode like this:
bash
bash -i
bash -ic 'echo Hello!'
When you run a script through bash(1) or if you start it with the -c option,
it will run in non-interactive mode:
bash script.sh
bash -c 'echo Hello!'
bash(1) is instructed to act as a login shell when you first log in to your
machine or when you start bash(1) with the --login or -l option.
.bashrc is sourced on every start in interactive mode when bash(1) does not
act as a login shell.
.bash_profile is only sourced when bash(1) is started as an interactive
login shell, or as a non-interactive shell with the --login option.
This means that .bash_profile is great for commands that should run only once
and .bashrc for commands that should run every time you start a new shell.
For example, PATH customization should only happen once, since it is not an
idempotent operation. Suppose something like this was in your .bashrc:
export PATH="$PATH:/addition"
Running these commands from a newly started interactive shell would produce the
output below:
bash
bash
echo "$PATH"
/original_path:/addition:/addition:/addition
Setting PATH in .bash_profile alleviates this problem.