The tcsh is an enhanced but completely compatible version of the Berkeley UNIX C shell, csh. 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 and many other features. This page shows how to export csh or tcsh variable using the command line option on Linux or Unix-like operating systems.
FreeBSD display current environment variables
Type the following command to print current names and values of environment variables under tcsh or csh:
SHELL=/usr/local/bin/bash TERM=xterm SSH_CLIENT=10.10.29.66 37484 22 SSH_TTY=/dev/ttyp2 USER=root PAGER=more FTP_PASSIVE_MODE=YES PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin MAIL=/var/mail/root BLOCKSIZE=K PWD=/root SHLVL=2 HOME=/root LOGNAME=root SSH_CONNECTION=10.10.29.66 37484 10.24.116.2 22 _=/bin/csh HOSTTYPE=FreeBSD VENDOR=unknown OSTYPE=FreeBSD MACHTYPE=unknown GROUP=wheel HOST=vps.nixcraft.in REMOTEHOST=10.10.29.66 EDITOR=vim
Export shell variable
To export and set new environment variables, enter:
setenv name value
setenv EDITOR /usr/bin/vim
You need to add all your environment variables to ~/.cshrc file – csh resource script, read at beginning of execution by each shell. Here is my sample .cshrc file:
alias h history 25 alias j jobs -l alias la ls -a alias lf ls -FA alias ll ls -lA # A righteous umask umask 22 set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin $HOME/bin) setenv EDITOR vim setenv PAGER less setenv BLOCKSIZE M if ($?prompt) then # An interactive shell -- set some stuff up set prompt = "`/bin/hostname -s`# " set filec set history = 100 set savehist = 100 set mail = (/var/mail/$USER) if ( $?tcsh ) then bindkey "^W" backward-delete-word bindkey -k up history-search-backward bindkey -k down history-search-forward endif endif
A list of commonly used tcsh environment variables
An array of strings called the environment is made available by execve() call when a process begins. By convention these strings have the form name=value. The following names are used by various commands
- BLOCKSIZE : The size of the block units used by several commands, most notably df, du and ls. BLOCKSIZE may be specified in units of a byte by specifying a number, in units of a kilobyte by specifying a number followed by K or k, its of a megabyte by specifying a number followed by M or m etc.
- COLUMNS : The user’s preferred width in column positions for the terminal. Utilities such as ls and who use this to format output into columns.
- EDITOR : Default editor name.
- EXINIT : A startup list of commands read by ex and vi.
- HOME : A user’s login directory, set by login from the password file /etc/passwd.
- LANG : This variable configures all programs which use setlocale to use the specified locale unless the LC_* variables are set.
- MAIL : The location of the user’s mailbox instead of the default in /var/mail, used by mail, sh, and many other mail clients.
- PAGER : Default paginator program. The program specified by this variable is used by mail, man, ftp, etc, to display information which is longer than the current display.
- PATH : The sequence of directories, separated by colons, searched by csh, sh, system, execvp, etc, when looking for an executable file. PATH is set to /usr/bin:/bin initially by login.
- PRINTER : The name of the default printer to be used by lpr, lpq, and lprm.
- PWD : The current directory pathname.
- SHELL : The full pathname of the user’s login shell.
- TERM : The kind of terminal for which output is to be prepared. This information is used by commands, such as nroff or plot which may exploit special terminal capabilities.
- TMPDIR : The directory in which to store temporary files. Most applications use either /tmp or var/tmp. Setting this variable will make them use another directory.
- TZ : The timezone to use when displaying dates.
- USER : The login name of the user.
tcsh export variable
The syntax is as follows to define a new tcsh or csh variable named life with 42 as value:
setenv life 42
To print value of the $life use printf command/echo command:
printf "%d\n" $life
Now start a new tcsh session (children tcsh session):
Find out if children inherit environment variable named $life:
env | grep life
A list of csh export variable commands
- env OR env | grep var_name – Set environment and execute command, or print environment variables
- setenv name value – Sets the environment variable name to value and export it too
- echo "$var_name" OR printf "%FORMAT" $var_name – Display value of the environment variable name
- man page – csh, tcsh