我正在尝试创建一个全局计数器变量来查看~/.profile执行了多少次。因此:
在~/.bashrc:
# ...
if [ "$PROFILE_EXEC_TIMES" = "" ]; then
export PROFILE_EXEC_TIMES=0
fi
let "PROFILE_EXEC_TIMES += 1"
Run Code Online (Sandbox Code Playgroud)
在~/.profile:
# ...
export PROFILE_EXEC_TIMES
let "PROFILE_EXEC_TIMES += 1"
Run Code Online (Sandbox Code Playgroud)
但是当我打开一个新的 shell 并写入时echo $PROFILE_EXEC_TIMES,我得到的只是1. $PROFILE_EXEC_TIMES必须至少为 2。我怀疑这~/.profile不是由 bash 提供的……如果是这样,我需要做什么来检查~/.profile执行了多少次?
编辑:
我注意到通过以下行/etc/gdm/Xsession采购~/.profile:
test -f "$HOME/.profile" && . "$HOME/.profile"
Run Code Online (Sandbox Code Playgroud)
并~/.bashrc来源于~/.profile以下几行:
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
Run Code Online (Sandbox Code Playgroud)
另外,我已将以下行添加到~/.bashrc& ~/.profile:
echo $(cd ${0%/*} && echo $PWD/${0##*/}) >> /home/myUserName/a
Run Code Online (Sandbox Code Playgroud)
并且可以看到在我登录到我的用户后只有一行被添加到文件中。
我想强调一下,我这里的目标是:
找出~/.profile用户登录时执行了多少次。
额外细节:
$ uname -a
Linux my-desktop 2.6.32-25-generic #45-Ubuntu SMP Sat Oct 16 19:52:42 UTC 2010 x86_64 GNU/Linux
$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04.1 LTS"
Run Code Online (Sandbox Code Playgroud)
从您对我的原始答案的评论来看,您真正的问题似乎是“~/.profile 是否来自 GNOME?” 答案是肯定的。进去看看/etc/gdm/Xsession:
# First read /etc/profile and .profile
test -f /etc/profile && . /etc/profile
test -f "$HOME/.profile" && . "$HOME/.profile"
# Second read /etc/xprofile and .xprofile for X specific setup
test -f /etc/xprofile && . /etc/xprofile
test -f "$HOME/.xprofile" && . "$HOME/.xprofile"
Run Code Online (Sandbox Code Playgroud)
从 bash 的联机帮助页:
当 bash 作为交互式登录 shell 或作为具有 --login 选项的非交互式 shell 调用时,它首先从文件 /etc/profile 读取并执行命令(如果该文件存在)。读取该文件后,它会按该顺序查找
~/.bash_profile、~/.bash_login、 和~/.profile,并从第一个存在且可读的命令中读取和执行命令。
因此,您的主目录中可能有一个名为 .bash_profile 或 .bash_login 的文件。如果其中任何一个存在,bash 将使用它而不是 .profile。
| 归档时间: |
|
| 查看次数: |
2474 次 |
| 最近记录: |