How do I set environment variables using c shell (tcsh or csh) under FreeBSD UNIX or Linux operating systems? How do I save variable using csh shell under Unix like operating systems?
You can use set or setenv command under c shell to set an environment variable.
The c shell use the following syntax to set an enviroment variables.
setenv syntax
The syntax is:
setenv var value
In this example, set an enviroment variables in the csh (and tcsh) called vech to bus:
setenv vech bus
To display the value for $vech, enter:
echo "$vech"
OR
printf "%s\n" "$vech"
To see all variables, type:
setevn
Sample outputs:
_=/bin/csh OLDPWD=/home/vivek PWD=/home/vivek SHLVL=2 USER=vivek LOGNAME=vivek HOME=/home/vivek MAIL=/var/mail/vivek PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/vivek/bin TERM=xterm FTP_PASSIVE_MODE=YES BLOCKSIZE=K SHELL=/usr/local/bin/zsh SSH_CLIENT=192.168.1.5 57038 22 SSH_CONNECTION=192.168.1.5 57038 192.168.1.109 22 SSH_TTY=/dev/pts/0 HOSTTYPE=FreeBSD VENDOR=unknown OSTYPE=FreeBSD MACHTYPE=unknown GROUP=vivek HOST=fdbsd9 REMOTEHOST=192.168.1.5 EDITOR=vi PAGER=more
set command syntax
The syntax is:
set var=val set foo=bar echo "$foo"
~/.cshrc file
You can setenv and other commands in a $HOME/.cshrc file. This file is located in your home directory that is read whenever a c shell starts. The .login file is read after the .cshrc file when this is a login script. In this example, set default pager to most and add to ~/.cshrc file
echo 'setenv PAGER most' >> $HOME/.cshrc
csh: set vs setenv
You use the set or setenv commands to initialize a variable, where set is used for current shell and setenv for current and any subshells (i.e. it will automatically export variables to subshell). setenv should be used for PATH, HOME, and all other system related environmental settings. Use set command in your csh script only.
- 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














{ 0 comments… add one now }