Perform Swapping Operation using two variables bash shell programming in Linux UNIX script programming


By using three variables it will perform the swap operation. These basic swap operation. And you can do also perform swapping with two variables. a=a+b, a>b,b=a-b, a=a-b;
Example a=7,b=5, a=7+5; a=12 ,b=12-5=7,a=12 -7=5 finally a=5 and b=7 these swap operation perform by using only two variable.
Source code bash shell Programming Algorithm
echo “ First value ”
read a
echo “ Second value ”
read b
echo “ The swapped value: ”
echo “ First value = $a ”
echo “ Second value = $b ”

using two variable to perform the swap operation

OUPUT CS1252 Operating Systems lap
[redhat35@localhost Rhel5]$ sh
First value
Second value
The swapped value is:
First value = 10
Second value = 23

No comments:
Write comments