Professional Documents
Culture Documents
V.chandrasekharan Mech 024 Program: to display the name and time in the given format #shell script
#!/bin/sh echo enter your name read x echo welcome $x echo now the time is [`date +%H:%M:%S`]
sample input and output: enter your name shyam Welcome shyam Now the time is [12:00:18]
V.chandrasekharan Mech 024 Program: to find the area of circle and rectangle #shell script #!/bin/sh echo enter the radius read x c =`echo 22/7 \* $x \* $x |bc l` echo the area of circle is $c echo enter the length read l echo enter the breadth read b r =`echo $l \* $b |bc -l` echo the area of rectangle is $r sample input and output: enter the radius 5 The area of circle is 78.50 Enter the length 4 Enter the breadth 3 The area of rectangle is 12
V.chandrasekharan Mech 024 Program: to write a program to convert Fahrenheit to Celsius #shell script #!/bin/sh echo enter the Fahrenheit value read f p=`echo $f - 32 | bc -l`
cel=`echo $p / 1.8 | bc -l` echo the Celsius value is $cel sample input and output: enter the Fahrenheit value 212 Celsius value is 100.00000
V.chandrasekharan Mech 024 Program: to write a shell program to display the output of given commands #shell script #!/bin/sh echo the list of directories available echo `ls` echo list of login users echo `who` echo todays date echo `date` echo count of *.sh files echo `ls *.sh |wc` sample input and output: the list of directories of directories available -b desktop documents library movies music pictures public college
f1.txt the current working directory /users/mech14 The list of login users Mech14 Mech14 console ttyp1 jan 1 jan 1 05:30
05:30
todays date is thu jan 1 05:30:26 IST 1970 count of *.sh files 0
V.chandrasekharan Mech 024 Program: to find the sum of n numbers #shell script #!/bin/sh echo enter the number of terms read n s=0 i=1 if [ $N ] while [ $i -le $N ] do s=`expr $s + $i ` i=`expr $i +1` done fi echo the sum is $s sample input and output: enter the number of terms 5 The sum is 15
V.chandrasekharan Mech 024 Program: to find maximum of three numbers #shell script #!/bin/sh echo enter three numbers read a read b read c if [ $a -gt $b -a $a -gt $c ] then echo $a is big elif [ $b -gt $a -a $b -gt $c ] then echo $b is big else echo $c is big fi sample input and output: 1)enter three numbers 10 25 45 45 is big
V.chandrasekharan Mech 024 Program: to find the factorial of given number #shell script #!/bin/sh Echo enter the number Read n s=1 i=n while [ $i -ge 1 ] do s=`expr $i \* $f` i=`expr $i - 1` done echo the factorial of $n is $s sample input and output: enter the number 5 The factorial of 5 is 120
V.chandrasekharan Mech 024 Program: to check whether the given number is prime or not #shell script #!/bin/sh echo enter a number read n b=0 for((i=2;i<$n;i++)) do c=`expr $n % $i` if [ $c -eq 0 ] then b =1 fi done if [ b -eq 0 ] then echo $n is prime else echo $n is not prime fi
V.chandrasekharan Mech 024 Program: to check if the given number is Armstrong or not #shell script #!/bin/sh echo enter the number read n a=$n sum=0 while [ $n -ne 0 ] do r=`expr $n %10` s=`expr $r \*r \*r` sum=`expr $sum +$s` n=`expr $n /10` done if [ $a -eq $s ] then echo the number is Armstrong else echo the given number is not Armstrong fi