Swapping two number using a Shell Program. I tried this in Ubuntu Linux. Saved with the extension of .sh, and i run this program by using sh <filename>. Lets try out and tell any query if there.
Note : Refer How To Copy The Following Code From This Site:
- Content Stoling is prevented on this site.
- So Refer the Link to copy the below coding part by using this >>> link <<<
[sourcecode language=’css’]
echo “SWAP TWO NUMBERS USING TWO VARIABLES”
echo “Enter the value of two numbers”
read a
read b
echo “Enter the value of two numbers”
echo “a=$a , b=$b”
a=$ [ $a + $b ]
b=$ [ $a – $b ]
a=$ [ $a – $b ]
echo “After swapping the values are:”
echo “a=$a , b=$b”
[/sourcecode]
Output:
SWAP TWO NUMBERS USING TWO VARIABLES
Enter the value of two numbers
a=5
b=10
After swapping the values are:
a=10
b=5
Thanks Balaji for sharing these useful and best suggestions with us. keeep up the right and great work. thanks again for taking time to write such useful posts.
Thanks ! for easy logic.