0% found this document useful (0 votes)
748 views

Shell Script To Find Largest and Smallest of Given 3 Numbers

This document contains 4 shell script assignments: 1) A script to find the largest and smallest of 3 numbers input by the user. 2) A script to count the number of words, characters, spaces, and special characters in a string input by the user and determine if a given character is a vowel or consonant. 3) A script to determine if a year input by the user is a leap year or not. 4) A script to determine if a number input by the user is even or odd.

Uploaded by

Siddhant Bhalla
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
748 views

Shell Script To Find Largest and Smallest of Given 3 Numbers

This document contains 4 shell script assignments: 1) A script to find the largest and smallest of 3 numbers input by the user. 2) A script to count the number of words, characters, spaces, and special characters in a string input by the user and determine if a given character is a vowel or consonant. 3) A script to determine if a year input by the user is a leap year or not. 4) A script to determine if a number input by the user is even or odd.

Uploaded by

Siddhant Bhalla
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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