I'm trying to create a global counter variable to see how many times ~/.profile gets executed. Thus:
In ~/.bashrc:
# ...
if [ "$PROFILE_EXEC_TIMES" = "" ]; then
export PROFILE_EXEC_TIMES=0
fi
let "PROFILE_EXEC_TIMES += 1"
In ~/.profile:
# ...
export PROFILE_EXEC_TIMES
let "PROFILE_EXEC_TIMES += 1"
But when I open a new shell and write echo $PROFILE_EXEC_TIMES, all I get is 1. $PROFILE_EXEC_TIMES must be at least 2. I suspect that ~/.profile isn't sourced by bash... if so, what I need to do in order to check how many times ~/.profile is executed?
Edit:
I've noticed that /etc/gdm/Xsession is sourcing ~/.profile by the following line:
test -f "$HOME/.profile" && . "$HOME/.profile"
and ~/.bashrc is sourced in ~/.profile by the following lines:
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
Also, I've add the following line to ~/.bashrc & ~/.profile:
echo $(cd ${0%/*} && echo $PWD/${0##*/}) >> /home/myUserName/a
and could see that only one line was added to the file after I logged in to my user.
I want to emphasize that my goal here is:
Finding out how many times ~/.profile is executed when user logs in.
Additional details:
$ 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"
- My /etc/gdm/Xsession
- My ~/.bashrc
- My ~/.profile
date >> /tmp/profile_runs. Then you can count the number of lines that has bee appended.wc -l < /tmp/profile_runs. – geirha Feb 3 '11 at 23:08