setenv Command Tutorial To Add, Delete and Change Environment Variables In Linux
Linux and Unix ecosystem mainly used command line based. While working with command line and C Shell we generally need some values to use with commands. Shells provide environment variables for this. This environment variables can be managed with
setenv command like add, change and remove.
setenv command is very simple we just need to provide the variable name and data
setenv VARIABLENAME DATA
List All Environment Variables
We can use
setenv in order to list all environment variables currently defined in C Shell.
Add Environment Variable
We will start by creating come environment variable and setting some data to it. We can use lowercase or uppercase letters bu the general usage is uppercase letters. In this case we will create a variable named
MYIP and set value
$ setenv MYIP 192.168.1.10
Print Environment Variable
We can print specific environment variable with
echo command. We will provide the environment variable and and prefix with
$ . In this example we will print environment variable named
MYIP like below.
$ echo $MYIP
Pass Environment Variables To Sub or Child Shell
Linux process and shell architecture provides the ability to run sub process or shell. Sub process and shell will create a new environment. If we need to use current environment variables in the sub process or shell we just need to use them accordingly. For example in the following example we will print previously defined
MYIP in the
$ echo $MYIP
Set OR Update One Environment Variable Value
After assigning a value to a environment variable we may need to update it with new value. We can use
set command in order to update current environment variable with a new value. In this example we will update our variable MYIP with
$ set MYIP=192.168.1.20
Useful Environment Variables
There are a lot of default enviroment variables. Here are some of them.
USERstores current user name
PWDcurrent working directory
SSH_CLIENTthe ssh client IP address with source and destination port numbers