Programs Using Linux Shell Script: S.No No
Programs Using Linux Shell Script: S.No No
Page
No
S.No
1)
2)
3)
4)
5)
6)
7)
8)
9)
10)
1
2
3
4
5
6
7-8
9
10
72
b=`expr $a - $b`
a=`expr $a - $b`
echo "After swapping "
echo "A = $a B = $b"
OUTPUT:
"1swpwitouttemp.sh" [New] 11L, 185C written
[David@linuxstuserver ses2]$ sh 1swpwitouttemp.sh
enter two numbers10
20
Before swapping
A = 10 B = 20
After swapping
A = 20 B = 10
[David@linuxstuserver ses2]$
OUTPUT:
"2swpwittemp.sh" [New] 11L, 148C written
[David@linuxstuserver ses2]$ sh 2swpwittemp.sh
enter two numbers100
200
Before swapping
A = 100 B = 200
After swapping
A = 200 B = 100
[David@linuxstuserver ses2]$
OUTPUT:
"3sqrcub.sh" [New] 7L, 150C written
[David@linuxstuserver ses2]$ sh 3sqrcub.sh
enter a number10
the squre of 10 is 100
the cube of 10 is 1000
[David@linuxstuserver ses2]$
then
echo even
else
echo odd
fi
OUTPUT:
enter the number
5
odd
[David@linuxstuserver ses2]$
OUTPUT:
enter a filename
aaa
aaa is a ordinary file
[David@localhost ses2]$
OUTPUT:
Files and Directories are @ present
aaa b bbb case.sh jj
MENU
1.display a file
2.copy a file
3.create a directory
enter ur choice
1
enter filename to display the content of......
aaa
clear
echo -e "Files and Directories are @ present \n"
ls
echo -e "\n\n"
echo -e "MENU\n\n1.display a file"
echo 2.copy a file
echo 3.create a directory
echo enter ur choice
read ch
case $ch in
1) echo enter filename
read fname
cat $fname
ls
;;
2) echo enter two files for copying from one to another
read file1 file2
cp $file1 $file2
ls
;;
3) echo enter the directory
read dname
mkdir $dname
ls
;;
*) echo invalid option
esac
[David@localhost ses2]$
then
echo equal
else
echo unequal
fi
OUTPUT:
enter a string1
abcxyz
enter a string2
abcxyz
equal
[David@linuxstuserver ses2]$
10
SOURCE CODE:
if [ $1 = $2 ]
then
echo "Strings are equal ...."
else
echo "Strings are not equal....."
fi
OUTPUT
[David@linuxstuserver ses2]$ sh 9cmp2strcmdline.sh vasavi vasavi
Strings are equal ....
[David@linuxstuserver ses2]$ sh 9cmp2strcmdline.sh vasavi ivasav
Strings are not equal.....
[David@linuxstuserver ses2]$
11
OUTPUT:
9strlength.sh" [New] 6L, 123C written
David@linuxstuserver ses2]$ sh 9strlength.sh
Enter the string vasavi college
the length of the string is 14
David@linuxstuserver ses2]$
12