Roll No: 312211114111 Name: VAIBHAV PRAKASH

1. Write a Shell Script to display the following shell environmental variables like User, Login name, Present Working Directory, OS type and Shell. $cat >shell1.sh echo "User Name :” $USER echo -n "Login Name :” whoami echo -n "Present Working Directory :” $PWD echo "Operating System : “ $OSTYPE echo "Shell Programming" $sh shell1.sh Output:User Name : SSN Student Login Name : mech111 Present Working Directory : /home/mech111/shell Operating System : Solaris Shell Programming 2. Write a Shell Script to get your name as input from the user and display the output with time. $cat >shell1.sh echo -n "Enter your Name : " read nm echo "Welcome $nm" tm=$(date +"%H:%M:%S") echo "Now the time is $tm" $sh shell1.sh

sh echo "Enter the radius : " read r echo "Area of the circle is" `expr 3.Output :Enter your Name : mech111 Welcome mech111 Now the time is 10:34:55 3. Write a Shell Program to find the area of the circle and rectangle.sh .50 Enter the length : 10 Enter the breadth : 20 Area of the rectangle is 200 4.14 \* $r \* $r` echo "Enter the length :" read l echo "Enter the breadth :" read b echo "Area of the rectangle is" `expr $l \* $b` $sh shell1.sh echo "Enter the temperature in fahrenheit :" read f echo "Temperature in celsius = " `expr ($f .sh Output :Enter the radius : 5 Area of the circle is 78. $cat >shell1. Write a Shell Program to convert Fahrenheit to Celsius.32) \*0. $cat >shell1.556` $sh shell1.

Write a Shell Script to get two filename as command line arguments.sh files and system’s date.696 5. list of login users.sh echo "Listing Directory" ls echo "Current Working Directory" pwd echo "List of users logged on" who -q echo "Number of *. $cat >shell1.sh Output :Listing Directory a.sh files 5 System's Date 02/04/2012 6.sh s1 s10 s2 s3 s4 s5 s6 s7 s8 s9 Current Working Directory /exam/mech111/shell1 List of users logged on mech111 # users=1 Number of *. Write a Shell Program to work out the following commands : list directory. current working directory. Check .sh files" ls *.Output :Enter the temperature in fahrenheit : 98 Temperature in celsius = 36.sh | wc -m echo "System's Date" date +"%d/%m/%Y" $sh shell1. count of *.

sh input.txt File1 Hello File2 Good Morning File2 Good Morning Hello 7. else produce error message and return. $cat>shell1.txt readtxt.$2 if [-f $1 –a –f $2 ] then echo “File 1” `cat $1` echo “File 2” `cat $2` cat $1>>$2 echo “File 2” `cat $2` else echo “Sorry! Files do not exist!” fi else echo ”Sorry incorrect argument!” fi $sh shell1. $cat>shell1.txt readtxt.sh if [$# -eq 2]. Write a Shell Script to get 2 filename as command line input. Check for correct count.sh input. then echo “Filenames are” $1 . If both file exists then append the content of second file into first file.txt Output:Filenames are input.txt .the correct argument count supplied in command line. If both the files exist then Sort the content of both the files and merge it into third filename obtained from the user. Display the filenames.txt readtxt.sh if [$# -eq 2 ] then if [-f $1 –a –f $2 ] then echo “Enter the name of the file in which the sorted contents are to be written” read name echo “Contents of $1” `cat $1` echo “Contents of $2” `cat $2` sort $1 $2 >$name cat $name else echo “Sorry! Files do not exist” fi else echo “Incorrect Argument count” fi $sh shell1.

Display the details of pattern students. Write a Shell Script to get a filename and pattern to be searched as command line arguments.sh opfile 4 7 Output:Gold Green Lavender Orange 9. Check for proper count.sh if [$# -eq 3] then c=`wc –l $1|cit –d ‘ ‘ –f1` if [$c –gt $3 –a $3 –gt $2 ] then c=`expr $3 . Display the no.txt CEG TECHOFES SSN INTINCTS CEG TECHOFES 8.sh if [$# -eq 2] then if [-f $1] then echo “Number of CSE students” `grep –c –i CSE $1` echo “Details of matching Students” `grep $2 $1` echo “Details of Non-CSE studnets” `grep –v CSE $1` else echo “File doesn’t exist” . Write a Shell Program to get the filename . Display the lines from lower to upper limit of the given file Ex : sh show. of CSE students.sh file1. Display the non-cse students information. $cat>shell1.c 7 10 ---(7 to 10 lines in file1.Output:Enter the name of the file in which the sorted contents are to be written Opfile Contents of input.c should be displayed) $cat >shell1. (pattern can be either name or branch).txt SSN INSTINCTS Contents of readtxt. lower limit and upper limit as command line arguments. Consider file contains student names and branch details.$2 + 1` head –n $3 $1|tail –n $c else echo “Invalid Arguments” fi else echo ”Invalid” fi $sh shell1.

If so delete the lines which contains the word “unix”.fi else echo ”Invalid” fi $sh shell1.sh input.sh if [-f $1] then if [-w $1] then echo ”Contents”. Check whether file exits and it has write permission.txt Output:Contents This is SSN Unix rocks! Contents This is SSN .sh input. cat $1 grep –v unix $1>newfile mv newfile $1 echo “Contents” cat $1 else echo ”Not writable” fi else echo “Doesn’t exist” fi $sh shell1. Write a Shell Program to get a file as input from user.txt MECH Output:Number of CSE students 2 Details of Matching students Simpsons 9 MECH 98 Details of Non Matching students Raj 8 BME 11 10. $cat>shell1.

Sign up to vote on this title
UsefulNot useful