0% found this document useful (0 votes)
6 views6 pages

Shell Script Programs

The document contains a collection of shell script programs that perform various tasks, including swapping variable values, converting Fahrenheit to Centigrade, determining the largest of three numbers, grading based on marks, identifying vowels or consonants, performing basic arithmetic operations, generating multiplication tables, reversing numbers, and checking for prime numbers. Each script is accompanied by example outputs demonstrating its functionality. These scripts serve as practical examples for learning shell scripting.

Uploaded by

jsric26
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Shell Script Programs

The document contains a collection of shell script programs that perform various tasks, including swapping variable values, converting Fahrenheit to Centigrade, determining the largest of three numbers, grading based on marks, identifying vowels or consonants, performing basic arithmetic operations, generating multiplication tables, reversing numbers, and checking for prime numbers. Each script is accompanied by example outputs demonstrating its functionality. These scripts serve as practical examples for learning shell scripting.

Uploaded by

jsric26
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Shell Script Programs

A) Swapping Values of Two Variables ([Link])

echo -n "Enter value for A : "

read a

echo -n "Enter value for B : "

read b

t=$a

a=$b

b=$t

echo "Values after Swapping"

echo "A Value is $a and B Value is $b"

Output:

$ sh [Link]

Enter value for A : 12

Enter value for B : 23

Values after Swapping

A Value is 23 and B Value is 12

B) Fahrenheit to Centigrade Conversion ([Link])

echo -n "Enter Fahrenheit : "

read f

c=`expr \( $f - 32 \) \* 5 / 9`

echo "Centigrade is : $c"

Output:

$ sh [Link]
Enter Fahrenheit : 213

Centigrade is : 100

C) Biggest of Three Numbers ([Link])

echo -n "Give value for A B and C : "

read a b c

if [ $a -gt $b -a $a -gt $c ]

then

echo "A is the Biggest number"

elif [ $b -gt $c ]

then

echo "B is the Biggest number"

else

echo "C is the Biggest number"

fi

Output:

$ sh [Link]

Give value for A B and C : 4 3 4

C is the Biggest number

D) Grade Determination ([Link])

echo -n "Enter the mark : "

read mark

if [ $mark -gt 90 ]

then

echo "S Grade"

elif [ $mark -gt 80 ]


then

echo "A Grade"

elif [ $mark -gt 70 ]

then

echo "B Grade"

elif [ $mark -gt 60 ]

then

echo "C Grade"

elif [ $mark -gt 55 ]

then

echo "D Grade"

elif [ $mark -ge 50 ]

then

echo "E Grade"

else

echo "U Grade"

fi

E) Vowel or Consonant ([Link])

echo -n "Key in a lower case character : "

read choice

case $choice in

a|e|i|o|u) echo "It's a Vowel" ;;

*) echo "It's a Consonant" ;;

esac

F) Simple Calculator ([Link])

echo -n "Enter the two numbers : "


read a b

echo "1. Addition"

echo "2. Subtraction"

echo "3. Multiplication"

echo "4. Division"

echo -n "Enter the option : "

read option

case $option in

1) c=`expr $a + $b`

echo "$a + $b = $c" ;;

2) c=`expr $a - $b`

echo "$a - $b = $c" ;;

3) c=`expr $a \* $b`

echo "$a * $b = $c" ;;

4) c=`expr $a / $b`

echo "$a / $b = $c" ;;

*) echo "Invalid Option" ;;

esac

G) Multiplication Table ([Link])

clear

echo -n "Which multiplication table? : "

read n

for x in 1 2 3 4 5 6 7 8 9 10

do

p=`expr $x \* $n`

echo "$n X $x = $p"

sleep 1
done

H) Number Reverse ([Link])

echo -n "Enter a number : "

read n

rd=0

while [ $n -gt 0 ]

do

rem=`expr $n % 10`

rd=`expr $rd \* 10 + $rem`

n=`expr $n / 10`

done

echo "Reversed number is $rd"

I) Prime Number ([Link])

echo -n "Enter the number : "

read n

i=2

m=`expr $n / 2`

until [ $i -gt $m ]

do

q=`expr $n % $i`

if [ $q -eq 0 ]

then

echo "Not a Prime number"

exit

fi

i=`expr $i + 1`
done

echo "Prime number"

You might also like