# History of commands csh



## pavlar (May 4, 2020)

I can  select the commands    using the arrow only in root and the user can't do it. How to make  the user's select of commands by arrow?
I did csh.cshrc:

```
set savehist = (8192 merge)
set savedirs = 100
set tperiod = 10
alias   periodic        '(history -S & dirs -S & )'
dirs -L
history -M # workaround for ssh(1) logins
```

Did not help


----------



## Beastie (May 4, 2020)

First of all check the output of `echo $0` to make sure the user is actually using t/csh.

/etc/csh.cshrc is a system-wide configuration. As a personal preference I usually leave it alone and only modify the individual .cshrc files, e.g. /root/.cshrc, /home/pavlar/.cshrc, etc.

What you're looking for are the *history-search-backward* and *history-search-forward* commands that are bound to the *up* and *down* keys. They may be missing in your RC file. Check the reference RC in the source tree (lines 40 and 41).


----------



## pavlar (May 4, 2020)

Excuse me, this is strange, but I have user's shell:

```
echo $SHELL
/bin/sh
```
root's shell

```
echo $SHELL
/bin/tcsh
```
User's .shrc

```
alias h='fc -l'
alias j=jobs
alias m="$PAGER"
alias ll='ls -laFo'
alias l='ls -l'
alias g='egrep -i'
```


----------



## pavlar (May 4, 2020)

In user's  .shrc script of reference dont work 

```
if ($?prompt) then
                # An interactive shell -- set some stuff up
                set prompt = "%N@%m:%~ %# "
                set promptchars = "%#"

                set filec
                set history = 1000
                set savehist = (1000 merge)
                set autolist = ambiguous
                # Use history to aid expansion
                set autoexpand
                set autorehash
                set mail = (/var/mail/$USER)
                if ( $?sh ) then
                        bindkey "^W" backward-delete-word
                        bindkey -k up history-search-backward
                        bindkey -k down history-search-forward
                endif

        endif
```



```
-sh: Syntax error: "(" unexpected (expecting "fi"
```


----------



## pavlar (May 4, 2020)

And I can't changing user sh to tcsh in /etc/passwd - sh does not change 

```
cat /etc/shells
# $FreeBSD: releng/12.1/lib/libc/gen/shells 336840 2018-07-28 20:21:23Z brd $
#
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/sh
/bin/csh
/bin/tcsh
/usr/local/bin/tcsh
/usr/local/bin/bash
/usr/local/bin/rbash
```


----------



## pavlar (May 4, 2020)

I added a new user and chose tcsh. Here everything is in order  by arrow's selecting of  history of commands.. This decision suits me. Thank.  And with the previous user, nothing happens . I will remove it so as not to waste time


----------



## VladiBG (May 4, 2020)

Never ever modify the passwd file by hand. To select a different shell use `chsh`. (you need to know basic vi(1) commands to edit it)
If you somehow edit passwd file you need to regenerate the master.passwd https://www.freebsd.org/cgi/man.cgi?pwd_mkdb


----------



## pavlar (May 4, 2020)

I use  only nano or editor mc  or ee  .Vi is very  uncomfortable.  /etc/passwd и /etc/group I am editing with  vipw(8) and vigr(8).


----------



## SirDice (May 4, 2020)

pavlar said:


> I use only nano or editor mc or ee .Vi is very uncomfortable.


Set the EDITOR variable to a different editor, then vipw(8)/vigr(8) will use that editor.


```
If	the following environment variable exists it will be utilized by vipw:

     EDITOR	      The editor specified by the string EDITOR	will be	in-
		      voked instead of the default editor vi(1).  This can be
		      used to allow a script to	non-interactively modify the
		      password file.
```


----------



## VladiBG (May 4, 2020)

vi is used by default unless you specify different editor in .profile

but again instead of editing the file it's very easy just to type

`chsh -s /bin/csh`
and after you relog your new shell will be csh


----------



## SirDice (May 4, 2020)

VladiBG said:


> vi is used by default unless you specify different editor in .profile


~/.profile is only read by Bourne shells, not by the C shells.


----------



## VladiBG (May 4, 2020)

Yes his user is using /bin/sh which is controlled by ~/.profile when he switch to csh he's env will be read by ~/.cshrc that's why for his user he must specify the env using .profile file.






						sh
					






					www.freebsd.org


----------



## pavlar (May 4, 2020)

Thanks. But I just don’t like the look of the invitation :~ % . Can In somehow transform it?



```
ku@risk:~ % echo $0
-tcsh
ku@risk:~ %
```


----------



## SirDice (May 4, 2020)

pavlar said:


> Can In somehow transform it?


Edit ~/.cshrc:

```
# An interactive shell -- set some stuff up
        set prompt = "%N@%m:%~ %# "
        set promptchars = "%#"
```
See tcsh(1).


----------



## pavlar (May 4, 2020)

```
set prompt="%{^[[40;33;1m%}[%T] %{^[[40;32;1m%} %/ >"
[1] 4280
[15:55]  /home/ku >
```


----------



## SirDice (May 4, 2020)

```
switch($TERM)
                case "rxvt":
                case "screen*":
                case "xterm*":
                        set TITLE = "%{\033]0;%n@%m:%~\007%}"
                        breaksw
                default:
                        set TITLE = ""
                        breaksw
        endsw

        set prompt = "${TITLE}%B%n@%m%b:%c03 %# "
        unset TITLE
```
This sets the Xterm/PuTTY title the same as the prompt.


----------



## pavlar (May 4, 2020)

Where to write this expression  ( set prompt="%{^[[40;33;1m%}[%T] %{^[[40;32;1m%} %/ >") for tcsh? In my directory, only /.cshrc


```
ls -la
total 56
drwxr-xr-x  3 ku    ku      512 May  4 16:02 .
drwxr-xr-x  5 root  wheel   512 May  4 11:58 ..
-rw-------  1 ku    ku       12 May  4 16:02 .cshdirs
-rw-r--r--  1 ku    ku     1107 May  4 16:02 .cshrc
-rw-------  1 ku    ku     2960 May  4 16:02 .history
-rw-r--r--  1 ku    ku      392 May  4 11:36 .login
-rw-r--r--  1 ku    ku      163 May  4 11:36 .login_conf
-rw-------  1 ku    ku      379 May  4 11:36 .mail_aliases
-rw-r--r--  1 ku    ku      339 May  4 11:36 .mailrc
drwxr-xr-x  2 ku    ku      512 May  4 11:39 .mc
-rw-r--r--  1 ku    ku      954 May  4 11:36 .profile
-rw-r--r--  1 ku    ku      851 May  4 11:36 .shrc
-rwxr-xr-x  1 ku    ku      159 Feb 12 10:19 ban
-rwxr-xr-x  1 ku    ku      834 Jun 18  2019 cleaner
```


----------



## pavlar (May 4, 2020)

I put to .cshrc It works

```
# freebsd-update upgrade -r ${name_of_release}

        -- Lars Engels <lme@FreeBSD.org>
[16:13]  /home/ku >
```


----------



## SirDice (May 4, 2020)

pavlar said:


> Where to write this expression ( set prompt="%{^[[40;33;1m%}[%T] %{^[[40;32;1m%} %/ >") for tcsh? In my directory, only /.cshrc





SirDice said:


> Edit ~/.cshrc:


----------

