How will you set the value of Environment variables in Unix?

We can use ‘setenv’ command to set the value of environment variables.
E.g. % setenv [Name] [value]
% setenv MAX_TIME 10

To print the value of environment variable we can use ‘printenv’ command.
E.g. % printenv MAX_TIME

If we just use printenv then it lists all the environment variables and their values.

To unset or delete an environment variable we use unsetenv command.

E.g. % unsetenv MAX_TIME

To use an environment variable in a command we use the prefix $ with the name of variable.

What is the special rule about Shell and Environment variable in Bourne Shell?

In Bourne Shell, there is not much difference between Shell variable and Environment variable.

Once we start a Bourne Shell, it gets the value of environment variables and defines a corresponding Shell variable. From that time onwards the shell only refers to Shell variable. But if a change is made to a Shell variable, then we have to explicitly export it to environment so that other shell or child processes can use it.

Also for Shell variables we use set and unset commands.

Leave a Reply

Your email address will not be published. Required fields are marked *