我.bash_profile的如下:
alias l='ls -l'
alias p='pwd'
alias sites='cd /home/caveman/sites'
alias time_card='cd /home/caveman/sites/time-card/time-card'
alias ping='ping google.com'
alias bash_profile='gedit /home/caveman/.bash_profile'
alias webroot='cd /var/www'
Run Code Online (Sandbox Code Playgroud)
每次登录我的机器时,我都需要运行source .bash_profile以使所有别名可用。
各位大侠能看出问题出在哪里吗?
将~/.bash_profile仅在登录会话读取。
此外,有一个~/.bash_profile可以防止来源~/.profile,这是在bashUbuntu的配置中用于登录 shell 的首选文件。
当您登录显示管理器(我想是 GDM)时,~/.profile默认情况下会读取(我不知道 GDM 是否遵循bash规则并读取~/.bash_profile,如果存在)。
即使~/.bash_profile是从 GDM 读取的,别名也不会被继承,因此您在图形终端(不是登录外壳)中的外壳无法看到它们。
解决办法是:把你的别名放在~/.bashrc,并且只在非常简单的事情上使用别名,否则使用函数。
该文件~/.bashrc由非登录交互式 shell 读取,并且来自~/.profile,因此其内容也可在登录 shell 中使用。