# Where is history?



## tunage (Dec 21, 2015)

and how do I make it permanent?

```
[\u@r2d2:/root] # set -o
Current option settings
errexit off
noglob off
ignoreeof off
interactive on
monitor on
noexec off
stdin on
xtrace off
verbose off
vi off
emacs on
noclobber off
allexport off
notify off
nounset off
privileged off
trapsasync off
physical off
trackall off
[\u@r2d2:/root] # pkg search history
dnshistory-1.3_1 Store DNS lookups to a DB
pear-Horde_History-2.3.5 Horde API for tracking the history of an object
trytond28_account_invoice_history-2.8.0_1 Tryton Application Platform (Account Invoice History Module)
trytond28_product_cost_history-2.8.0_1 Tryton Application Platform (Product Cost History Module)
```


----------



## SirDice (Dec 21, 2015)

It's built into the shell.


----------



## tunage (Dec 21, 2015)

SirDice said:


> It's built into the shell.



where are the settings for it?
most importantly, how do you make it permanent?  Like forever?


Definitely not here

```
[\u@r2d2:/usr/local/sbin] # man history
BUILTIN(1)  FreeBSD General Commands Manual  BUILTIN(1)

NAME
  builtin, !, %, ., :, @, [, {, }, alias, alloc, bg, bind, bindkey, break,
  breaksw, builtins, case, cd, chdir, command, complete, continue, default,
  dirs, do, done, echo, echotc, elif, else, end, endif, endsw, esac, eval,
  exec, exit, export, false, fc, fg, filetest, fi, for, foreach, getopts,
  glob, goto, hash, hashstat, history, hup, if, jobid, jobs, kill, limit,
  local, log, login, logout, ls-F, nice, nohup, notify, onintr, popd,
  printenv, printf, pushd, pwd, read, readonly, rehash, repeat, return,
  sched, set, setenv, settc, setty, setvar, shift, source, stop, suspend,
  switch, telltc, test, then, time, times, trap, true, type, ulimit, umask,
  unalias, uncomplete, unhash, unlimit, unset, unsetenv, until, wait,
  where, which, while -- shell built-in commands

SYNOPSIS
  See the built-in command description in the appropriate shell manual
  page.

DESCRIPTION
  Shell builtin commands are commands that can be executed within the run-
  ning shell's process.  Note that, in the case of csh(1) builtin commands,
  the command is executed in a subshell if it occurs as any component of a
  pipeline except the last.
--More--(byte 2342)...skipping...
BUILTIN(1)  FreeBSD General Commands Manual  BUILTIN(1)   
   
NAME   
  builtin, !, %, ., :, @, [, {, }, alias, alloc, bg, bind, bindkey, break,   
  breaksw, builtins, case, cd, chdir, command, complete, continue, default,   
  dirs, do, done, echo, echotc, elif, else, end, endif, endsw, esac, eval,   
  exec, exit, export, false, fc, fg, filetest, fi, for, foreach, getopts,   
  glob, goto, hash, hashstat, history, hup, if, jobid, jobs, kill, limit,   
  local, log, login, logout, ls-F, nice, nohup, notify, onintr, popd,   
  printenv, printf, pushd, pwd, read, readonly, rehash, repeat, return,   
  sched, set, setenv, settc, setty, setvar, shift, source, stop, suspend,   
  switch, telltc, test, then, time, times, trap, true, type, ulimit, umask,   
  unalias, uncomplete, unhash, unlimit, unset, unsetenv, until, wait,   
  where, which, while -- shell built-in commands   
   
SYNOPSIS   
  See the built-in command description in the appropriate shell manual   
  page.

DESCRIPTION
  Shell builtin commands are commands that can be executed within the run-
  ning shell's process.  Note that, in the case of csh(1) builtin commands,
  the command is executed in a subshell if it occurs as any component of a
  pipeline except the last.

  If a command specified to the shell contains a slash `/', the shell will
  not execute a builtin command, even if the last component of the speci-
  fied command matches the name of a builtin command.  Thus, while specify-
  ing ``echo'' causes a builtin command to be executed under shells that
  support the echo builtin command, specifying ``/bin/echo'' or ``./echo''
  does not.

  While some builtin commands may exist in more than one shell, their oper-
  ation may be different under each shell which supports them.  Below is a
  table which lists shell builtin commands, the standard shells that sup-
  port them and whether they exist as standalone utilities.

  Only builtin commands for the csh(1) and sh(1) shells are listed here.
  Consult a shell's manual page for details on the operation its builtin
  commands.  Beware that the sh(1) manual page, at least, calls some of
  these commands ``built-in commands'' and some of them ``reserved words''.
  Users of other shells may need to consult an info(1) page or other
  sources of documentation.

  Commands marked ``No**'' under External do exist externally, but are
  implemented as scripts using a builtin command of the same name.

  Command  External  csh(1)  sh(1)
  !  No  No  Yes
  %  No  Yes  No
  .  No  No  Yes
  :  No  Yes  Yes
  @  No  Yes  No
  [  Yes  No  Yes
  {  No  No  Yes
  }  No  No  Yes
  alias  No**  Yes  Yes
  alloc  No  Yes  No
  bg  No**  Yes  Yes
  bind  No  No  Yes
  bindkey  No  Yes  No
  break  No  Yes  Yes
  breaksw  No  Yes  No
  builtin  No  No  Yes
  builtins  No  Yes  No
  case  No  Yes  Yes
  cd  No**  Yes  Yes
  chdir  No  Yes  Yes
  command  No**  No  Yes
  complete  No  Yes  No
  continue  No  Yes  Yes
  default  No  Yes  No
  dirs  No  Yes  No
  do  No  No  Yes
  done  No  No  Yes
  echo  Yes  Yes  Yes
  echotc  No  Yes  No
  elif  No  No  Yes
  else  No  Yes  Yes
  end  No  Yes  No
  endif  No  Yes  No
  endsw  No  Yes  No
  esac  No  No  Yes
  eval  No  Yes  Yes
  exec  No  Yes  Yes
  exit  No  Yes  Yes
  export  No  No  Yes
  false  Yes  No  Yes
  fc  No**  No  Yes
  fg  No**  Yes  Yes
  filetest  No  Yes  No
  fi  No  No  Yes
  for  No  No  Yes
  foreach  No  Yes  No
  getopts  No**  No  Yes
  glob  No  Yes  No
  goto  No  Yes  No
  hash  No**  No  Yes
  hashstat  No  Yes  No
  history  No  Yes  No
  hup  No  Yes  No
  if  No  Yes  Yes
  jobid  No  No  Yes
  jobs  No**  Yes  Yes
  kill  Yes  Yes  Yes
  limit  No  Yes  No
  local  No  No  Yes
  log  No  Yes  No
  login  Yes  Yes  No
  logout  No  Yes  No
  ls-F  No  Yes  No
  nice  Yes  Yes  No
  nohup  Yes  Yes  No
  notify  No  Yes  No
  onintr  No  Yes  No
  popd  No  Yes  No
  printenv  Yes  Yes  No
  printf  Yes  No  Yes
  pushd  No  Yes  No
  pwd  Yes  No  Yes
  read  No**  No  Yes
  readonly  No  No  Yes
  rehash  No  Yes  No
  repeat  No  Yes  No
  return  No  No  Yes
  sched  No  Yes  No
  set  No  Yes  Yes
  setenv  No  Yes  No
  settc  No  Yes  No
  setty  No  Yes  No
  setvar  No  No  Yes
  shift  No  Yes  Yes
  source  No  Yes  No
  stop  No  Yes  No
  suspend  No  Yes  No
  switch  No  Yes  No
  telltc  No  Yes  No
  test  Yes  No  Yes
  then  No  No  Yes
  time  Yes  Yes  No
  times  No  No  Yes
  trap  No  No  Yes
  true  Yes  No  Yes
  type  No**  No  Yes
  ulimit  No**  No  Yes
  umask  No**  Yes  Yes
  unalias  No**  Yes  Yes
  uncomplete  No  Yes  No
  unhash  No  Yes  No
  unlimit  No  Yes  No
  unset  No  Yes  Yes
  unsetenv  No  Yes  No
  until  No  No  Yes
  wait  No**  Yes  Yes
  where  No  Yes  No
  which  Yes  Yes  No
  while  No  Yes  Yes

SEE ALSO
  csh(1), echo(1), false(1), info(1), kill(1), login(1), nice(1), nohup(1),
  printenv(1), printf(1), pwd(1), sh(1), test(1), time(1), true(1),
  which(1)

HISTORY
  The builtin manual page first appeared in FreeBSD 3.4.

AUTHORS
  This manual page was written by Sheldon Hearn <sheldonh@FreeBSD.org>.

FreeBSD 10.1  December 21, 2010  FreeBSD 10.1
```


----------



## tunage (Dec 21, 2015)

```
# history
history: not found
```

WTF???


----------



## SirDice (Dec 21, 2015)

It depends on the shell you're using, not all shells have a history. Set root's shell to /bin/csh. The csh(1) and tcsh(1) shells both have a history.


----------



## max21 (Dec 21, 2015)

tunage said:


> ```
> # history
> history: not found
> ```
> ...



I know what you mean.  Sometime its crazy especially when you paid attention from the start.

I notice with every new version I installed, FreeBSD will not save anything to history for quite awhile.  After playing with a new version I would reboot and there is no history saved.  Sometimes it takes up to 5 or 10 shut-down or reboot before FreeBSD start saving history.  You could change the size in the .cshrc file and it will *sometimes* start working after a  reboot or two.  Then you can change it back if you like.  It’s kind of tricky, to which one to set.  I think it is /.cshrc.  Than /root/.cshrc will reset automatically … This could be reverse.  Never could figure that out… It really acts like it got a mind of its own sometimes.  But once it starts saving it will save up to the number you listed.  If you go over that number, your previous entries will be lost to make rome for your new entry that will be listed at the bottom.  I found this to really get quite sloppy because I like my db history numbers to stay consistence.

```
set history = 1000
set savehist = 1000
```
I have a little trick to keep my favorite .history list.   I put this in my reboot script along with a ton of other things I like to do at reboot or shutdown time.

```
#!/bin/sh
# #############################      Run at BOOT
rm /root/.history
sleep 1

cp -prv /root/_history_backup /root/.history
sleep 3

reboot
```


----------



## tunage (Dec 21, 2015)

This got it:
`chsh -s /usr/local/bin/bash root`


----------



## wblock@ (Dec 21, 2015)

Changing root's shell is a mistake.


----------



## tankist02 (Dec 22, 2015)

I also had problems with tcsh(1) history. So I enabled toor account and set shells/bash as shell for it.


----------



## drhowarddrfine (Dec 22, 2015)

To repeat:


wblock@ said:


> Changing root's shell is a mistake.


----------



## tobik@ (Dec 22, 2015)

That's what the toor account is for: https://www.freebsd.org/doc/en_US.ISO8859-1/books/faq/security.html#idp60186576


----------



## SirDice (Dec 22, 2015)

max21 said:


> I notice with every new version I installed, FreeBSD will not save anything to history for quite awhile.  After playing with a new version I would reboot and there is no history saved.  Sometimes it takes up to 5 or 10 shut-down or reboot before FreeBSD start saving history.


Yeah, I noticed that too. A `touch ~/.history` seems to fix it. Not sure why this is happening though.


----------



## ktm5j (Dec 29, 2015)

wblock@ said:


> Changing root's shell is a mistake.


Could you elaborate on why this is a mistake?


----------



## wblock@ (Dec 29, 2015)

https://www.freebsd.org/doc/en/articles/linux-users/shells.html


----------



## kpa (Dec 30, 2015)

getopt said:


> Is this true? I always found csh instead of tcsh.



It says /bin/csh in /etc/master.passwd but in reality it is tcsh(1). The real csh(1) is much more pedestrian shell than the very modern tcsh(1). If you want to see the difference run csh on OpenBSD that still carries the historical csh.


----------



## uzsolt (Dec 30, 2015)

getopt said:


> I always found csh instead of tcsh.




```
$ diff /bin/csh /bin/tcsh
$ # no differences
```


----------



## SirDice (Dec 31, 2015)

uzsolt said:


> ```
> $ diff /bin/csh /bin/tcsh
> $ # no differences
> ```




```
root@molly:~ # ls -li /bin/csh /bin/tcsh
1228254 -r-xr-xr-x  2 root  wheel  394736 Dec 27 01:54 /bin/csh
1228254 -r-xr-xr-x  2 root  wheel  394736 Dec 27 01:54 /bin/tcsh
```
As you can see by the inode numbers, they both refer to the same file (csh is a hardlink to tcsh).


----------



## uzsolt (Dec 31, 2015)

SirDice said:


> ```
> root@molly:~ # ls -li /bin/csh /bin/tcsh
> 1228254 -r-xr-xr-x  2 root  wheel  394736 Dec 27 01:54 /bin/csh
> 1228254 -r-xr-xr-x  2 root  wheel  394736 Dec 27 01:54 /bin/tcsh
> ...


An another solution


----------



## protocelt (Dec 31, 2015)

kpa said:


> It says /bin/csh in /etc/master.passwd but in reality it is tcsh(1). The real csh(1) is much more pedestrian shell than the very modern tcsh(1). If you want to see the difference run csh on OpenBSD that still carries the historical csh.


If you're really intent on punishing yourself, you can also install CSH from ports: shells/44bsd-csh


----------



## Profighost (Mar 9, 2022)

Sorry to reopen this one, but as I mentioned elsewhere I have the exact same problem with shell's history.
However, if csh is nothing but a hardlink to tcsh, so both are the same, why bsdconfig gives you still the option to chose one of both? 
As far as I understood what's written here, this would make no sense.


----------



## covacat (Mar 9, 2022)

the shell acts different when run as csh or tcsh
all* the stuff in /rescue is just one binary and they act different

also on most linux systems /bin/sh is linked to bash but acts more posix and without bash-isms


----------



## SirDice (Mar 9, 2022)

Profighost said:


> As far as I understood what's written here, this would make no sense.


Originally there was the C shell. Then someone extended the original C Shell by adding a bunch of features and called it tcsh. Tcsh is backwards compatible with csh. It switches "modes" based on the way it is called. It's rather pointless to maintain separate code for csh and tcsh, so the original csh code was removed and replaced with tcsh. Root's shell was kept as /bin/csh and thus runs tcsh(1) in csh(1) "mode". 


```
DESCRIPTION
       tcsh is an enhanced but completely compatible version of the Berkeley
       UNIX C shell, csh(1).  It is a command language interpreter usable both
       as an interactive login shell and a shell script command processor.  It
       includes a command-line editor (see The command-line editor),
       programmable word completion (see Completion and listing), spelling
       correction (see Spelling correction), a history mechanism (see History
       substitution), job control (see Jobs) and a C-like syntax.  The NEW
       FEATURES section describes major enhancements of tcsh over csh(1).
       Throughout this manual, features of tcsh not found in most csh(1)
       implementations (specifically, the 4.4BSD csh) are labeled with `(+)',
       and features which are present in csh(1) but not usually documented are
       labeled with `(u)'.
```
tcsh(1)

The same is done on several Linux distributions where /bin/sh and /bin/bash are the same executable. Executing /bin/sh simply runs bash(1) in a Bourne shell compatibility mode.


----------



## Profighost (Mar 9, 2022)

Thanks, I do know that all already.
That's not the point. The point was 


SirDice said:


> As you can see by the inode numbers, they both refer to the same file (csh is a hardlink to tcsh).



So what I understand what's written here in 2015 within FreeBSD csh and tcsh are the same. There is no difference between them. csh is hardlinked to tcsh. So there is no csh really. Either way you use tcsh.
That's completely fine by me - I prefer tcsh. It's my favorite shell.

My question was:
But then it would not make no sense to have a choice between csh and tcsh in bdsconfig if both is hardlinked to tcsh anyway.
Could be done as a choice between sh and tcsh, so for root no choice at all.


----------



## SirDice (Mar 9, 2022)

Profighost said:


> But then it would not make no sense to have a choice between csh and tcsh in bdsconfig if both is hardlinked to tcsh anyway.


When executed as /bin/csh it runs tcsh(1) in C shell mode, disabling all those extra features. So there is a difference in the way /bin/csh and /bin/tcsh act. Historically root's shell was set to /bin/csh and they kept it that way.


----------



## Profighost (Mar 9, 2022)

Ah, okay, I see.
So there is a difference in the usage. Okay.
Thanks.


----------



## SirDice (Mar 9, 2022)

Profighost said:


> So there is a difference in the usage. Okay.


Yes, that's it. Although they both refer to the exact same executable, the way that executable works is different depending on the way it is being called. 


```
root@armitage:/tmp # ls -li someexe blah
316 -rwxr-xr-x  2 root  wheel  139 Mar  9 16:49 blah
316 -rwxr-xr-x  2 root  wheel  139 Mar  9 16:49 someexe
root@armitage:/tmp # ./blah
Running in 'blah' mode
root@armitage:/tmp # ./someexe
Running in normal mode
root@armitage:/tmp # cat someexe
#!/bin/sh

MYNAME=$(basename "$0")

if [ $MYNAME = 'blah' ]; then
  echo "Running in 'blah' mode"
else
  echo "Running in normal mode"
fi
```
Simplest example I could think of. Both someexe and blah refer to the same file (the inodes are the same). The code checks how  it's being called (that's stored in $0 in shell, in C it would be in `argv[0]`).


----------



## Vull (Mar 9, 2022)

covacat said:


> the shell acts different when run as csh or tcsh
> all* the stuff in /rescue is just one binary and they act different
> 
> also* on most linux systems /bin/sh is linked to bash* but acts more posix and without bash-isms



FWIW, on Linux Mint, and, I'm pretty sure, all of the Debian branch, /bin/sh links to dash (the Debian Almquist shell):
	
	



```
len@lenovo:~$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Apr  5  2021 /bin/sh -> dash
len@lenovo:~$ which dash
/usr/bin/dash
len@lenovo:~$
```






						Almquist shell - Wikipedia
					






					en.wikipedia.org


----------

