Solved csh history file

I really like how well the autocompletion together with history works on the default FreeBSD csh shell.
Wondering about the backup of command line history in .cshrc

set history = 8000
set savehist = (8000 merge)

So after 8000 commands it auto saves and starts a new .history file?
 
No, it's on a first-in, last-out basis. It's more like a rotating buffer where new commands causes the oldest to be removed.
 
However usually .history is updated right before logout, hence new commands will not be shared amongst concurrent sessions. You can save/load history buffer manually, see csh(1), search for history -c.
 
Nice to see more people who enjoy the C Shell.

Despite the fact that its primary focus is for interaction it also allows you to use it for scripting. So you could always consider adding this to ~/.cshrc:

Code:
set HIST="~/.history"

if (`wc --libxo text -l ${HIST} | cut -d '/' -f1` == 2000) then
        mv ${HIST} ${HIST}.old
        touch ${HIST} && chmod 600 ${HIST}
endif
Maybe you could then set up a cron job to to more with the old file, I dunno. Figured I'd share :)
 
I really like how well the autocompletion together with history on the default FreeBSD csh shell.
Wondering about the backup of command line history in .cshrc

set history = 8000
set savehist = (8000 merge)

So after 8000 commands it auto saves and starts a new .history file?

What if you put something like:

Code:
alias precmd 'history -S; history -M'

In your ~/.tcshrc, thus to save and merge your history for each new prompt line printed instead of shell logout? :)

I also like to set the $HISTFILE variable, since it happens, from time to time, to switch shell (e.g., to use utilities like youtube-dl or stream link,which require a Bourne-compliant shell)
 
That is interesting. I had assumed env settings were on a per shell basis. I had no idea it was system-wide
They are not system-wide -- setting an environment variable in your current shell won't affect running processes, or processes started from a different session. Each process has its own environment and each sub-process (a command you execute, like ls(1) or a shell/Perl/Python/whatever script) inherits environment of current shell/process. Usually set builtin(1) prints current shell variables, whereas printenv(1) shows environment (exported) variables.
 
That is interesting. I had assumed env settings were on a per shell basis. I had no idea it was system-wide

Well, probably I my words resulted confusioning: naturally it can be setsystem-wide, but you're right, it 's wiser to have a per shell configuration; since the ENV in rewritten by shells's rc files when a sew shell prompt is printed, I like to set different ${histfile} for each shell I use (e.g., ~/.tchsh_history & ~/.msksh_history for when I switch to mksh ;) ) otherwise shells which default to the same histfile would mess each other's history
 
Back
Top