我是 Ubuntu 的新手。我正在运行 13.10 桌面版。
我想为 bash 设置一些系统范围的别名和自定义提示。我找到了这篇文章:
https://help.ubuntu.com/community/EnvironmentVariables
按照本文中的建议,我创建了 /etc/profile.d/profile_local.sh。它归 root 所有,并且与那里的其他脚本一样具有 644 的权限:
root@ubuntu:/etc/profile.d# ll
total 28
drwxr-xr-x 2 root root 4096 Mar 23 08:56 .
drwxr-xr-x 135 root root 12288 Mar 23 09:15 ..
-rw-r--r-- 1 root root 660 Oct 23 2012 bash_completion.sh
-rw-r--r-- 1 root root 3317 Mar 23 07:36 profile_local.sh
-rw-r--r-- 1 root root 1947 Nov 23 00:57 vte.sh
Run Code Online (Sandbox Code Playgroud)
我进一步确认 /etc/profile 调用 /etc/profile.d。它包含以下代码块:
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if …Run Code Online (Sandbox Code Playgroud) 我想将我所有的登录配置集中在我的~/.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) 我希望每次打开 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是最佳实践,我会这样做。