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?
| Tutorial details | |
|---|---|
| Difficulty | Easy |
| Root privileges | No |
| Requirements | C-shell |
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
csh
Try to display $vech, enter:
echo "$vech"
Sample outputs:
vech: Undefined variable.
Now, try same with setenv command:
setenv jaildir /nas/httpd echo "$jaildir" csh echo "$jaildir"
Sample outputs:
/nas/httpd
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.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 2 comments… read them below or add one }
So does setenv work with all shells or just csh?
[t]csh is not recommended for scripting:
Top Ten Reasons not to use the C shell
Csh problems
Csh Programming Considered Harmful