Cómo puedo recargar.bashrc sin cerrar sesión y volver a entrar?
Si hago cambios en .bashrc
, ¿cómo puedo recargarlo sin cerrar sesión y volver a entrar?
14 answers
Solo tienes que introducir el comando:
source ~/.bashrc
O puede usar la versión más corta del comando:
. ~/.bashrc
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-09 17:47:54
O podrías usar;
exec bash
, Hace lo mismo. (y más fácil de recordar, al menos para mí)
exec command reemplaza el shell con un programa dado, en nuestro ejemplo, reemplaza nuestro shell con bash (con los archivos de configuración actualizados)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-01 08:59:00
A complementar y contrastar las dos respuestas más populares, . ~/.bashrc
y exec bash
:
Ambas soluciones efectivamente recargar ~/.bashrc
, pero hay diferencias:
-
. ~/.bashrc
osource ~/.bashrc
lo hará conserva tu shell actual :- Excepto por las modificaciones que reloading
~/.bashrc
en el shell actual (sourcing) hace, el shell actual y su estado son preservado, que incluye variables de entorno, variables de shell, opciones de shell, funciones de shell e historial de comandos.
- Excepto por las modificaciones que reloading
-
exec bash
, o, más robusto,exec "$BASH"
[1], will reemplace su shell actual con una nueva instancia, y por lo tanto solo conserva las variables de entorno de tu shell actual (incluyendo los que has definido ad-hoc).- En otras palabras: Cualquier cambio ad-hoc para el shell actual en términos de variables del shell, las funciones del shell, las opciones del shell, el historial de comandos se pierden.
Dependiendo de sus necesidades, uno u otro enfoque puede ser preferido.
[1] exec bash
podría en teoría ejecutar un diferente bash
ejecutable que el que inició el shell actual, si sucede que existe en un directorio listado anteriormente en el $PATH
. Dado que la variable especial $BASH
siempre contiene la ruta completa de la ejecutable que inició el shell actual, exec "$BASH"
está garantizado para usar el mismo ejecutable.
Una nota re "..."
alrededor de $BASH
: las comillas dobles aseguran que el valor de la variable se use tal cual, sin interpretación por Bash; si el valor no tiene espacios incrustados u otros metacaracteres del shell (lo cual no es probable en este caso), no necesita estrictamente comillas dobles, pero usarlas es un buen hábito para formar.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-13 01:27:54
Alguien editó mi respuesta para agregar un inglés incorrecto, pero aquí estaba el original, que es inferior a la respuesta aceptada.
. .bashrc
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-25 13:26:56
Dependiendo de su entorno, simplemente escriba
bash
También puede funcionar.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-08 11:51:51
Con esto, no ni siquiera tendrá que escribir "source ~/.bashrc":
Incluye tu archivo bashrc:
alias rc="vim ~/.bashrc && source ~/.bashrc"
Cada vez que desee editar su bashrc, simplemente ejecute el alias "rc "
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-26 22:24:02
. ~/.bashrc
Alternativas
source ~/.bashrc
exec bash
exec
command reemplaza el shell con un programa dado... - WhoSayIn
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-14 17:36:26
Tipo:
source .bashrc
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-03-25 18:00:15
Utilizo el siguiente comando en msysgit
. ~/.bashrc
Versión abreviada de
source ~/.bashrc
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-02 20:32:33
Esto también funcionará..
cd ~
source .bashrc
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-21 19:16:52
He notado que el comando pure exec bash
preservará las variables de entorno, por lo que necesita usar exec -c bash
para ejecutar bash en un entorno vacío.
Por ejemplo, inicia sesión en un bash, y export A=1
, si exec bash
, el A == 1
.
Si exec -cl bash
, A
está vacío.
Creo que esta es la mejor manera de hacer su trabajo.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-22 13:53:48
Para mí lo que funciona cuando cambio el CAMINO es: exec "$BASH" --login
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-08 20:13:16
Dependiendo de su entorno, es posible que desee agregar scripting a have .bashrc se carga automáticamente al abrir una sesión SSH. Recientemente hice una migración a un servidor que ejecuta Ubuntu, y allí,.perfil, no .bashrc or .bash_profile se carga de forma predeterminada. Para ejecutar cualquier script .bashrc, tuve que ejecutar source ~/.bashrc
cada vez que se abría una sesión, lo que no ayuda cuando se ejecutan implementaciones remotas.
Para tener su .bashrc se carga automáticamente al abrir una sesión, intente agregar esto a .perfil:
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
Vuelva a abrir su sesión, y debería cargar todas las rutas / scripts que tenga.bashrc.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-10-04 12:11:49
Yo personalmente tengo
alias ..='source ~/.bashrc'
En mi bashrc, para que solo pueda usar".."para recargarlo.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-20 03:49:20