How To Set or Export Environment Variable in FreeBSD

This post will guide you how to set or export environment variable in csh shell under FreeBSD system. How do I export shell variable using setenv command in your FreeBSD system.

Set or Export Environment Variable in FreeBSD 1

 

List Current Environment Variable


The default shell program for FreeBSD system is csh. And there is no export command to export environment variable directly. So if you want to set shell variable in your FreeBSD shell prompt, and you need to use another command called setenv.

Let’s check the default shell program by running the following command:

$ cat /etc/passwd | grep ^root

Outputs:

root@freebsd:~ # cat /etc/passwd | grep ^root
root:*:0:0:Charlie &:/root:/bin/csh

To list all current Environment variables at the csh shell prompt, you can type the following command:

$ setenv

or

$ env

Outputs:

root@freebsd:~ # setenv
USER=root
LOGNAME=root
HOME=/root
MAIL=/var/mail/root
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin
TERM=xterm
BLOCKSIZE=K
SHELL=/bin/csh
SSH_CLIENT=192.168.3.58 50394 22
SSH_CONNECTION=192.168.3.58 50394 192.168.3.45 22
SSH_TTY=/dev/pts/0
HOSTTYPE=FreeBSD
VENDOR=amd
OSTYPE=FreeBSD
MACHTYPE=x86_64
SHLVL=1
PWD=/root
GROUP=wheel
HOST=freebsd
REMOTEHOST=192.168.3.58
EDITOR=vi
PAGER=less

Set Environment Variable


If you want to set or export a Environment variable at csh shell prompt in your FreeBSD system, and you can type the following setenv command:

$ setenv variablename variableValue
$ setevn mytest 2000

Outputs:

root@freebsd:~ # setenv mytest 2000
root@freebsd:~ #
root@freebsd:~ #
root@freebsd:~ # setenv | grep mytest
mytest=2000
root@freebsd:~ #

root@freebsd:~ # env | grep mytest
mytest=2000

Conclusion


You should know that how to set or export environment variable at csh/tcsh shell prompt from the command line in your FreeBSD system.

You might also like:

Sidebar



back to top