FreeBSD Display Environment Settings

Q. How do I display shell environment settings under FreeBSD operating systems?

A. Use the env utility to print or modify environment settings. It executes another utility after modifying the environment as specified on the command line. Each name=value option specifies the setting of an environment variable, name, with a value of value. All such environment variables are set before the utility is executed.

ADVERTISEMENTS

Task: Display Environment Settings

Type the following command:
$ env
Sample output:

USER=vivek
LOGNAME=vivek
HOME=/iscsi/home/vivek
MAIL=/iscsi/home/vivek/mail
TERM=xterm
FTP_PASSIVE_MODE=YES
BLOCKSIZE=K
SHELL=/bin/csh
HOSTTYPE=FreeBSD
VENDOR=unknown
OSTYPE=FreeBSD
MACHTYPE=unknown
SHLVL=1
PWD=/tmp
GROUP=admins
HOST=pub.nixcraft.in
EDITOR=vi
PAGER=more

Task: Set new environment variable

Simply use set command:
$ set VAR=VALUE
$ set X = 5
$ set vech=Car
# set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin $HOME/bin)

You can also use setenv command:
$ setenv EDITOR vim
$ setenv PAGER less

.cshsrc file

You can add all variable to ~/.chsrc file under csh shell which is read at beginning of execution by each shell.
$ vi ~/.cshrc
Sample file:

alias h         history 25
alias j         jobs -l
alias la        ls -a
alias lf        ls -FA
alias ll        ls -lA

umask 22

set path = (/bin /usr/bin /usr/games /usr/local/sbin /usr/local/bin $HOME/bin)

setenv  EDITOR  vim
setenv  PAGER   less
setenv  BLOCKSIZE       K

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

Task: View environment variable value

Use echo command, enter:
$ echo $PATH
$ echo $X

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
2 comments… add one
  • saul figueiredo Jun 7, 2011 @ 12:05

    ok but how do I PATH variable to be loaded at boot always with the content I want?

  • dave Mar 1, 2012 @ 0:15

    How to UNset?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.