Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
PID TTY TIME CMD
11192 pts/4 00:00:00 bash
11653 pts/4 00:00:00 ps
$ echo "before history test"
before history test
$ history -a
$ echo "begin history test"
begin history test
$ bash
$ echo "in history test"
in history test
$ exit
exit
$ echo "end history test"
end history test
$ history |tail -9
1236 ps
1237 history
1238 ps
1239 echo "before history test"
1240 history -a
1241 echo "begin history test"
1242 bash
1243 echo "end history test"
1244 history |tail -9
all my input after --->echo "in history test"<--- is lost in history.
Last edited by jackandking; 10-21-2008 at 09:26 PM.
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
....When an inter-
active shell exits, the last $HISTSIZE lines are copied from the his-
tory list to $HISTFILE. If the histappend shell option is enabled (see
the description of shopt under SHELL BUILTIN COMMANDS below), the lines
are appended to the history file, otherwise the history file is over-
written. If HISTFILE is unset, or if the history file is unwritable,
the history is not saved. After saving the history, the history file
is truncated to contain no more than HISTFILESIZE lines. If HISTFILE-
SIZE is not set, no truncation is performed.
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
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
Do it before your history|tail stuff and you will se that the output is quite different
"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
PID TTY TIME CMD
3506 pts/12 00:00:00 bash
3674 pts/12 00:00:00 ps
$ echo "before history test"
before history test
$ shopt |grep append
histappend on
$ bash
$ echo "in history test"
in history test
$ exit
exit
$ echo "end history test"
end history test
$ history |tail -10
1342 env
1343 export PS1=$
1344 export PS1=$\
1345 ls
1346 ps
1347 echo "before history test"
1348 shopt |grep append
1349 bash
1350 echo "end history test"
1351 history |tail -10
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.