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
Environment
Steps
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
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
Was this topic helpful?
Document Information
Modified date:
25 October 2021
UID
ibm16457637