据说非登录shell的设置进入.bashrc文件和登录shell设置进入.profile文件。
登录和非登录 shell 的真正含义是什么?
请尽量不使用技术术语进行解释。
我想将我所有的登录配置集中在我的~/.bash_profile. ~/.bashrc默认情况下有一个那里,但我用一个~/.bash_profile.
但是,当我登录时,在~/.bash_profile获取源之前的某些内容并显示以下内容:
Linux ubnt10-dev1 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux
Ubuntu 10.04.4 LTS
Welcome to the Ubuntu Server!
* Documentation: http://www.ubuntu.com/server/doc
System information as of Fri May 9 12:17:39 EDT 2014
System load: 0.01 Processes: 74
Usage of /: 5.5% of 18.58GB Users logged in: 0
Memory usage: 4% IP address for eth0: 123.x.x.x
Swap usage: 0%
Graph this data and manage this system at https://landscape.canonical.com/
New …Run Code Online (Sandbox Code Playgroud) 到目前为止,我曾经在bash.bashrc文件中设置环境变量。最近我被告知要使用该/etc/environment文件。嗯,两者都工作正常。
那么,它们之间有什么区别呢?
我用谷歌搜索了这个,我发现“bashrc 用于特定的用户和环境,系统范围”。这里的系统范围是什么意思?/etc/bash.bashrc我猜也在系统范围内应用更改。如果我错了,请纠正我。任何形式的帮助将不胜感激..
我的~/Documents目录是一个符号链接:
nathan@nathan-desktop:~$ stat Documents
File: Documents -> /mnt/nathan/extended/Documents
Run Code Online (Sandbox Code Playgroud)
如果我想cd进入目录,我可以输入:
c d space D o c tab
...并且选项卡完成将按预期附加uments到末尾cd Doc。但是,它并没有附加一个尾随/,即使符号链接指向一个目录。
有没有办法让 Bash 做到这一点?
我希望每次打开 shell 时都可以使用以下别名:
export ZONE="us-eastern1-c"
export INSTANCE_NAME="myInstance"
alias gc='gcloud compute ssh --zone=$ZONE jupyter@$INSTANCE_NAME -- -L 8080:localhost:8080'
Run Code Online (Sandbox Code Playgroud)
我应该把它放进去.bashrc还是.profile?另外,扫描.bashrc我发现:
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Run Code Online (Sandbox Code Playgroud)
那么,这里的最佳做法是什么?我应该将别名(和所需的环境变量)放在第三个文件中.bash_aliases吗?我不是配置文件扩散的忠实粉丝,但如果使用这.bash_aliases是最佳实践,我会这样做。
我遇到这个问题是因为我想通过在 /etc/environment 中的 PATH 末尾添加另一个目录来扩展所有用户的 PATH 变量。
打开新的 shell 或新的登录都没有显示扩展的路径。
我发现 /etc/environment 上的保护设置为
-rw-r--r-- 1 root root 588 May 13 12:08 /etc/environment
Run Code Online (Sandbox Code Playgroud)
将 /etc/environment 设置为可执行文件为我解决了这个问题。