I‘ve recently started to use FreeBSD operating system with tcsh (c shell clone) shell. I noticed that both set and setenv command set shell user environment. What’s the difference between the SET and SETENV commands?
C Shell: set vs setenv
The c shell (tcsh or csh) sits between you and the operating system. It act as a command interpreter. It reads your command and translates the commands into actions taken by the Unix system. When the c shell starts up it reads its startup files and may set environment variables using setenv command.
All variables set with setenv command are automatically exported to subshell. All csh variables set to with set command are NOT automatically exported to subshell. In this example, set an enviorment variable called vech using set command:
set vech=bus echo "$vech"
Start a new shell
Try to display $vech, enter:
vech: Undefined variable.
Now, try same with setenv command:
setenv jaildir /nas/httpd echo "$jaildir" csh echo "$jaildir"
In short, set command is used for this shell and setenv for this and any subshells. Usually, all system environmental variable such as $HOME, $USER, $MAIL, $PATH, and others are defined using setenv command.Share this tutorial on: