≡ Menu

FreeBSD csh / tcsh: Export Shell Variable

Q. I'm using FreeBSD 7 with csh (tcsh) shell. How do I export shell variable under FreeBSD operating systems?

A. 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.

FreeBSD display current environment variables

Type the following command to print current names and values of environment variables:
Sample output:

SSH_CLIENT= 37484 22

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 enviorment 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

A list of commonly used 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.

Further readings:

  • man page - csh, tcsh

{ 3 comments… add one }

  • David Mackintosh September 2, 2008, 3:48 pm

    Might interest you to know that when I read your posts in my RSS Google Reader, I always get a pop-up demanding some credentials.

    See: http://wiki.xdroop.com/gallery2/v/Random/0809/20080902-1140001.jpg.html

  • Rabindra Nayak August 25, 2010, 4:17 pm

    if ($?prompt) then
    set prompt = “`/bin/hostname -s`# ”
    What does “($?prompt)” indicate in the code?

  • systemBuilder June 29, 2012, 11:06 pm

    The ($?prompt) term queries the shell, asking if the variable $prompt is set or not.

Leave a Comment

   Tagged with: , , , , , , , , , , ,