Estoy tratando de crear una variable de contador global para ver cuántas veces ~/.profile
se ejecuta Así:
En ~/.bashrc
:
# ...
if [ "$PROFILE_EXEC_TIMES" = "" ]; then
export PROFILE_EXEC_TIMES=0
fi
let "PROFILE_EXEC_TIMES += 1"
En ~/.profile
:
# ...
export PROFILE_EXEC_TIMES
let "PROFILE_EXEC_TIMES += 1"
Pero cuando abro un nuevo shell y escribo echo $PROFILE_EXEC_TIMES
, todo lo que obtengo es 1
. $PROFILE_EXEC_TIMES
debe ser al menos 2. Sospecho que ~/.profile
no proviene de bash... si es así, qué debo hacer para verificar cuántas veces ~/.profile
se ejecuta?
Editar:
He notado que /etc/gdm/Xsession
está obteniendo ~/.profile
por la siguiente línea:
test -f "$HOME/.profile" && . "$HOME/.profile"
y ~/.bashrc
se encuentra en ~/.profile
por las siguientes líneas:
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
Además, agregué la siguiente línea a ~/.bashrc
&~/.profile
:
echo $(cd ${0%/*} && echo $PWD/${0##*/}) >> /home/myUserName/a
y pude ver que solo se agregó una línea al archivo después de iniciar sesión en mi usuario.
Quiero enfatizar que mi objetivo aquí es:
Descubrir cuántas veces ~/.profile
se ejecuta cuando el usuario inicia sesión.
Detalles adicionales:
$ 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"
- Mi /etc/gdm/Xsession
- Mi ~/.bashrc
- Mi ~/.perfil
Respuesta aceptada:
De sus comentarios sobre mi respuesta original, parece que su verdadera pregunta es "¿Es ~/.profile procedente de GNOME?" La respuesta es sí. Busque en /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"
Respuesta original
Desde la página de manual de bash:
Cuando bash se invoca como un shell de inicio de sesión interactivo, o como un shell no interactivo
con la opción –login
, primero
lee y ejecuta comandos desde el archivo /etc/profile, si ese
archivo existe. Después de leer ese archivo,
busca ~/.bash_profile
, ~/.bash_login
y ~/.profile
, en ese orden, y
lee y ejecuta comandos desde el
primero
que existe y es legible.
Entonces, puede tener un archivo llamado .bash_profile o .bash_login en su directorio de inicio. Si alguno de estos existe, bash lo usará en lugar de .profile.
Relacionado:¿Cómo leer el valor de clave predeterminado con dconf o gsettings?