[ksh] how to reload history file without entering a command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [ksh] how to reload history file without entering a command
# 8  
Old 12-28-2018
Quote:
Originally Posted by DevuanFan
Perhaps most succinctly: Is there a command that flushes korn shell's history buffer and replaces it with contents of HISTFILE?
I am not really sure what you mean by that, but first let us be precise: are you talking about ksh88 (as it is found as the default shell in AIX and HP-UX) or ksh93?

Second, as far as i know there is no "history buffer" - apart from the history file - in ksh. You can have a separate history file for each shell instance (actually i like it that way because usually i need in a certain session the commands i used there before again, not the ones i used elsewhere, but that is a matter of personal taste) or you can have all sessions share a common history file. In each case "history" in the Korn shell is what is in this history file, nothing more, nothing less.

I hope this helps.

bakunin
# 9  
Old 12-28-2018
Quote:
Originally Posted by bakunin
as far as i know there is no "history buffer" - apart from the history file - in ksh...In each case "history" in the Korn shell is what is in this history file, nothing more, nothing less.
bakunin
Hi, bakunin. I'm finding that it is not so simple. If I have ksh running in a terminal emulator and manually edit the history file while the emulator is running, lines that I add to the HISTFILE will be picked up by the emulator. However, lines that I delete from the HISTFILE continue to show up in the terminal emulator's history. So it seems that the shell's idea of the history (which I'm calling its "history buffer") and what's actually in the HISTFILE are two different things. The only way for deleted lines to stop showing is to close the terminal emulator and open a new one.

Maybe my terminal emulator is introducing some unexpected behavior? I'll try a different emulator.

Thank you Jim and Neo. Yes, I'm finding that the only way to understand exactly what's going on will be to look at the source code. Alas, while my sh/bash, python, and perl kung fu is strong, C/C++ looks like gibberish to me, but I'll give it a shot anyway. If switching terminal emulators and/or recompiling ksh don't give me exactly the behavior I want, I may just go back to bash, which feels much more comfortable.

P.S. I'm using the public domain korn shell v5.2.14 (the default shell in OpenBSD 6.4).
# 10  
Old 12-28-2018
Quote:
Originally Posted by DevuanFan
P.S. I'm using the public domain korn shell v5.2.14 (the default shell in OpenBSD 6.4).
Well, pdksh is famous for being barely compatible with any real ksh, so i'd like to put what i said above in perspective: it was meant about "real" ksh-versions, mainly about ksh88 as found in AIX and ksh93 as found in AIX and Linux. The (real, AST) Korn shell was made open source IIRC 2005, so there is IMHO no reason to work with rather inept look-alikes (or, rather, look-similars) like the pdksh at all. Drop it and get a real Korn shell from github or kornshell.com.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 11  
Old 12-28-2018
Quote:
Originally Posted by DevuanFan
.... Alas, while my sh/bash, python, and perl kung fu is strong, C/C++ looks like gibberish to me, but I'll give it a shot anyway. If switching terminal emulators and/or recompiling ksh don't give me exactly the behavior I want, I may just go back to bash, which feels much more comfortable.
I recommend you open the C/C++ source code in a modern code editor, and having said that, I strongly recommend Visual Studio Code with the CPP extension:

C++ programming with Visual Studio Code

VSC also has extensions to prettify (format, beautify), indent, and to color matching brackets, braces and parens so all of this "cool stuff" makes code easier to read (and colorful, LOL)

Having the IntelliSense for CPP will help you understand the code. I write mostly in Javascript, PHP, CSS and HTML these days (nearly every day). VSC saves me a lot of time debugging syntax and keeping things moving along in a brisk development pace.
# 12  
Old 12-28-2018
Thanks, bakunin. I'm new to the Korn shell, so had no idea about these nuances. I see that ksh93 is in the OpenBSD package repository, so I'll install it and see how it's different from pdksh.

Neo, I will give VSC/IntelliSense a try. If it makes CPP easier to read and work with, I will probably really like it.

In the meantime, I'm back to bash for when I want to work and not play/explore. I find that having this in my .bashrc gives me exactly the behavior I expect (namely, any time I press Enter in a terminal, the shell's idea of the history matches exactly what is in my HISTFILE--no more, no less):
Code:
PROMPT_COMMAND="history -a; history -c; history -r"

Thank you all very much. Happy hacking!
# 13  
Old 12-28-2018
Quote:
Originally Posted by DevuanFan
I find that having this in my .bashrc gives me exactly the behavior I expect (namely, any time I press Enter in a terminal, the shell's idea of the history matches exactly what is in my HISTFILE--no more, no less):
Code:
PROMPT_COMMAND="history -a; history -c; history -r"

OK, i might be a bit slow but now i get what you want. If this is what you want you can have that in ksh too. There is no PROMPT_COMMAND variable in ksh but the shell prompt itself is capable of executing commands:

Code:
PS1='$(command; command; command; ...) <rest of your prompt here>'

Notice that editing the commad history needs the variable HISTEDIT (in ksh93) or FCEDIT (in ksh88) to be set to your preferred editor, otherwise you end up in ed. The history comamnd in ksh is hist, which by default is aliased to fc and r (for "repeat"). You can search and replace when repeating commands like this:

Code:
r old=new x

which will re-run the last command line starting with "x" but the instances of "old" replaced with "new".

I hope this helps.

bakunin

Last edited by bakunin; 12-28-2018 at 04:59 PM..
# 14  
Old 12-28-2018
I had tried that, but apparently pdksh there is no history command: 'history' is just an alias for 'fc -l'

So you're saying the "real" ksh has 'history' command with these flags? Nice! I'm sorry about the ksh version mixup. It's tough being a noob!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script not entering VRFY after nc command

I am making a bash script right now and am running into an issue. As I am new to scripting, I do not know exactly what to do to get what I'm looking for in my script. Essentially, my script will automatically input VRFY common names after nc Example: nc 192.168.248.133 25 VRFY Allison... (2 Replies)
Discussion started by: ksrhayward
2 Replies

2. AIX

Checking the command history file in AIX

Hello, The system has been rebooted and I need to see the commands executed in the system prior to restart by the oracle user.The history command is not showing me the commands executed prior to reboot. Please advise. Best regards, Vishal (1 Reply)
Discussion started by: Vishal_dba
1 Replies

3. Shell Programming and Scripting

UNIX CO command for file version history

Hello :) I'm a newb when it comes to shell scripting and was wondering about a command(s) for a script that could be used to checkout a certain number of version/revision histories of a file. I know for the latest revison you "co filename" or for a certain revision number "co -r*.* filename"... (2 Replies)
Discussion started by: MN-DBA
2 Replies

4. UNIX for Dummies Questions & Answers

Command to reload a zone

I just created a CNAME and i was told a zone needs to be reloaded after creating a CNAME. What is the command to reload a zone after the CNAME has been created? Thanks in advance (1 Reply)
Discussion started by: German Shepherd
1 Replies

5. Solaris

Login delay after entering id (40 secs) same after entering pw

Hi all, I have just installed Solaris 10 on an old Fujitsu Primepower 650 which has been wiped clean. I haven't installed anything apart from the OS yet, so the machine is 99% idle. I get long delays when logging in, first after entering the id then another long delay after entering a valid... (8 Replies)
Discussion started by: longjon
8 Replies

6. Shell Programming and Scripting

What is the ksh equivalent to bash's "history -c" command?

Hi, What is the korn shell equivalent of bash shell's "history -c" command? I do know, how to clear the history list in ksh, I can do the following: > ~/.sh_historybut still, I am interested to know the single one line command as 'history -c' gives error on my ksh (1 Reply)
Discussion started by: royalibrahim
1 Replies

7. Solaris

Command for checking modification history on file

What is the command for checking modification history on file? ---------- Post updated at 01:20 PM ---------- Previous update was at 12:35 PM ---------- Let me rephrase this. On a regular Unix file can I at least check to see the time and date history modification of the file? (6 Replies)
Discussion started by: jastanle84
6 Replies

8. UNIX for Dummies Questions & Answers

Reload user crontab file

Hi Guys, Our user crontab files are located at /var/spool/cron/crontabs. I have to make some modifications to it. I have all the crontab entries in a file called 'crontab.actual'. I made changes to this file and now I want to reload these changes from the crontab.actual file to my crontab... (12 Replies)
Discussion started by: vandi
12 Replies

9. UNIX for Dummies Questions & Answers

ksh: how to make [up arrow] recall command history

I want to get my up arrow key to recall my previous commands in Korn shell. Anyone help please? thanks a bunch! BG (3 Replies)
Discussion started by: BG_JrAdmin
3 Replies

10. UNIX for Dummies Questions & Answers

entering a long command

hello everyone! Very basic question for the guru's in here but anyways, I am trying to type a command that is longer than the line. What character do I use to continue my command on the next line? Thanks in advance.... Todd (1 Reply)
Discussion started by: hedrict
1 Replies
Login or Register to Ask a Question