IBM Support

Uniqueness of export and set commands in AIX

How To


Summary

Both set and export commands are used for setting the value of variable.Set is command to set the variable as local. The set command is primarily needed to set the environment you expect after you login to the system. We can unset its value it by running a command called unset. Closing the working session also makes the local variable unset. This is what it is said that set command is useful for creation of local variable.However export is mainly for the creation of global variable and it is get effected for each session we open.

Objective

Export and set commands are mainly used to set value to the variables. But they have their features and limitations in term of their effectiveness. This article is for the recommendation to the customer under what condition this command should be used.

Environment

AIX

Steps

Set Command:
The set command normally came in use for setting environment variable especially locale. A single set command can be used to set many variables but such a use is not recommended.The set command is mainly used for setting shell variable which is not propagated to the child shells.If you see the set command in AIX its mainly to control your environment in the profile file when you login, it helps in setting up your environment.
Example1:
set -o vi  # Enable users to use ‘vi’ commands to manipulate command line entry.

Example2:
One of the best tool in order to debug inside the script and command line.
 #set -x
 #set x=5.
+ set x=5 <-debug statement

Example3:
Very useful to create an array and initialize with the elements.
set -A test a01 a02 a03

Example4:
The simplest usage on command line and in .profile .
LANG=en_US
Export command:
Normally if you create a variable in shell and assign it some value, that value persists till the time shell
is alive and it vanishes as soon as session is closed. This is called local shell variable. If you need to make them persistent across shell you opened then you need to export those variable.So, basically exporting variable is making the variable as global .Again it is very useful in setting up commonly used environment variables like PATH and other libraries.
Example1:
PATH=/usr/java/bin;/usr/java/jre
This is called local because its life is limited to the current session.Export PATH
Now it is global across the shell you are opening as child .

Example2:
Multiple variable which are set can be exported together even
export A B=1 C D=2

Additional Information

Author: Tilak Nayak,Rajesh Kumar

Operating System: AIX and VIOS

Hardware: Power

Feedback: aix_feedback@wwpdl.vnet.ibm.com,tilak-r.nayak@in.ibm.com,rkumar11@in.ibm.com

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB08","label":"Cognitive Systems"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG10","label":"AIX"},"ARM Category":[{"code":"a8m0z0000001fMuAAI","label":"AIX General Support"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Version(s)"}]

Document Information

Modified date:
25 October 2021

UID

ibm16457637