how to change current bash to a login shell
if run "bash -l", ps will show two bash
PID TTY TIME CMD 10546 pts/5 00:00:00 bash 10578 pts/5 00:00:00 bash is there a way to change "current" bash to be a login shell? |
|
thanks for your replay, but chsh is not what i need.
maybe my words is not clear, what i want is: use bash as a login-shell from non-login shell without adding new process. |
The program that launches the shell is responsible for setting argv[0], thus indicating to the shell that it will be a login shell. You don't change this after the fact.
What problem are you trying to solve? |
I want to save all my input on cmdline by adding "history -a" to ~/.bash_logout
So, i need a login-shell |
It is not required that a shell be a login shell in order to save the history:
Code:
$ bash |
you are right if there is only one shell history in concern.
if I wanna store all my input on any running shell cmdline, non-login shell is not qualified. for example: Code:
$ ps |
The current shell does not re-read the history file when a child shell exits. Each shell retains its own in-core (memory) history. When the shell exits, that history list gets written out. It is a last-wins policy when the history is not appended, but overwritten. See man bash:
Code:
HISTORY |
In short, your issues has nothing to do with the shell being a login shell or not.
The only differences between a login shell and a non-login one are only relevant while the shell is starting (different rc files for login vs. non-login). There are some minor differences but nothing related to how the shell will work once it's been initialized. Maybe someone more knowledgeable can explain better :p If all you want to do is to reinitialize the shell, you can fork a new one causing the parent one to close by doing Code:
exec bash |
thanks to all of you!
"exec bash -l" can solve my problem. "shopt -s histappend" should solve it too, but not working in my test(still last-win): firstly, add "shopt -s histappend" to ~/.bashrc, then Code:
$ ps |
I'll repeat - the CURRENT shell does not re-read the history FILE each command. It WRITES the file upon exit. It only READS the history file upon STARTUP. So, the history command you run is only showing you the current shell's IN CORE history list. You're asking a child shell to fill its parent's history list.
|
finally, I understand, :)
thanks for your patient. |
That was the purpose of my "exec bash". It closes the current shell and substitutes it with a new one. That's why it works.
|
Right, and to make it REALLY appear / act as a login shell, add -a:
Code:
$ ps -p $$ |
All times are GMT -5. The time now is 08:42 AM. |