You are on page 1of 8

Siddhant Bhalla

19070124062

IT 3

ASSIGNMENT 4

1. Shell Script to find largest and smallest of given 3 numbers. 

INPUT-

#!/bin/sh

echo "plz enter the three numbers"

read x

read y

read z

if [ $x -ge $y ] && [ $x -ge $z ]

then

echo "$x is the largest number"

elif [ $y -ge $x ] && [ $y -ge $z ]

then

echo "$y is the largest number"

else
echo "$z is the largest number"

fi

if [ $x -lt $y ] && [ $x -lt $z ]

then

echo "$x is the smallest number"

elif [ $y -lt $x ] && [ $y -lt $z ]

then

echo "$y is the smallest number"

else

echo "$z is the smallest number"

fi

OUTPUT-
2) Shell script to calculate no. of words, characters and spaces of a given string. And find
out whether given character is vowel or consonant? 

INPUT-

#! /bin/bash

echo "Enter a String"

# Taking input from user

read text

# Counting words

word=$(echo -n "$text" | wc -w)

# Counting characters

char=$(echo -n "$text" | wc -c)


# Counting Number of white spaces (Here,specificly " ")

# sed "s/ change this to whitespace//g"

space=$(expr length "$text" - length `echo "$text" | sed "s/ //g"`)

# Counting special characters

special=$(expr length "${text//[^\~!@#$&*()]/}")

# Output

echo "Number of Words = $word"

echo "Number of Characters = $char"

echo "Number of White Spaces = $space"


echo "Number of Special symbols = $special"

OUTPUT-
3) Shell Script to find whether given year is leap or not

INPUT-

#!/bin/sh

echo "Enter the year"

read year
x=`expr $year % 400`

y=`expr $year % 100`

z=`expr $year % 4`

if [ $x -eq 0 ] || [ $y -ne 0 ] && [ $z –eq 0]

then

echo " Entered year - $year is a leap year"

else

echo "Entered year - $year is not a leap year "

fi

OUTPUT-
4) Shell Script to find whether given number  is odd or even 

INPUT-

echo “Enter any value for n:”

read n

a = `expr $n % 2`

if [ $a -eq 0 ]

then

echo “Given number $n is even”

else
echo “Given number $n is odd”

fi

OUTPUT-

You might also like