LSA10

i) Program that demonstrates the use of if..else with test

Create a vi editor to write the script:

vi Prog1.sh

Code:

echo Enter any number read n if test $n -gt 0 then           echo $n is positive else           echo $n is negative fi

steps forward

chmod +X Prog1.sh

bash Prog1.sh

ii) Program to check existing file Create a vi editor to write the script:

code:

echo Enter the file name: read fname if [ -f $fname ] then         echo the File Exists. else          echo the File with name $fname does not exists fi

iii) Program for string comparison Create a vi editor to write the script:

code:

echo Enter two Strings read str1 read str2 if [ $str1 = $str2 ] then          echo The strings are identical else          echo The Strings are not identical fi

iv) Program to check whether file has a permission to write Create a vi editor to write the script:

echo Enter the File name: read fname if [ -w $fname ] then           echo Type text to append. To stop press Ctrl + D.          cat >> $fname else          echo The has no write permission. fi

v) Program to give grades using expr command Create a vi editor to write the script:

code:

echo $per if [ $per -lt 35 ] then            echo Grade = Fail fi if [ $per -ge 35 -a $per -lt 45 ] then            echo Grade = Third fi if [ $per -ge 45 -a $per -lt 60 ] then          echo Grade = Second fi if [ $per -ge 60 -a $per -lt 75 ] then            echo Grade = First fi if [ $per -ge 75 ] then            echo Grade = First D fi

vi) Program to check whether the number is +ve or –ve usin elif Create a vi editor to write the script:

code:

echo Enter the number: read a if [ $a -lt 0 ] then          echo $a is Negative. elif [ $a -gt 0 ] then          echo $a is Positive. else          echo $a is ZERO. fi

vii) Program to print the day of the week using case.. in Create a vi editor to write the script:

code: echo Enter the Day Number: read num case $num in 1)             echo Sunday;; 2)             echo Monday;; 3)             echo Tuesday;; 4)             echo Wednesday;; 5)             echo Thursday:: 6)             echo Friday;; 7)             echo Saturday;; *)             echo Enter the number bet 1 to 7;; esac

viii) Program to find the pattern using case Create a vi editor to write the script

code: echo Enter the Word: read str case $str in [aeiou]*) echo The Word begins with a vowels;; [0-9]*) echo The word begins with a digit;; *[0-9]) echo The word ends with a digit;; '

????) echo The word entered is 4 lettered word;;

*) echo The word entered is either starts with a Constraints or incorrect input;; esac

ix) Menu Driven Program Create a vi editor to write the script:

code : echo Enter echo 1 To see the contents of /etc/passwd echo 2 To see list of users echo 3 To see present working directory echo 4 exit echo enter your choice read n case $n in 1)          cat /etc/passwd;; 2)          ls /home;; 3)          pwd;; 4)          exit;; *)          echo Enter the choice as 1, 2, 3, oг 4;; esac

x) Program to print first n number and their sum: while loop Create a vi editor to write the script:

code : i=1 sum=0 while [ $i -le 10 ] do             echo $i             sum=' expr $sum + $i '             i=' expr $i + 1 ' done echo The Sum is: $sum

xi) Program to print first n numbers and their sum: do..until Create a vi editor to write the script:

code: i=1 sum=0 until [ $i -gt 10] do          echo $i          sum= ' expr $sum + $i '         i= ' expr $i + 1 ' done echo The Sum is: $sum

xii) Program to illustrate the use of For Loop Create a vi editor to write the script:

code: sum=0 for i in 1 2 3 4 5 6 7 8 9 10 do          sum= ' expr $sum + $i '

         echo $i done echo The Sum is: $sum

xiii) Program to print summation 1+2+3+ -----n Create a vi editor to write the script:

code: echo Enter the Number: read n i=1 sum=0 while [ $i -le $n ] do             sum= ' expr $sum + $i '             i= ' expr $i + 1 ' done echo "Summnation = $sum"

xiv) Program to print table Create a vi editor to write the script:

code: j=1 echo Input Number: read n echo "Print Table of $n" for i in 1 2 3 4 5 6 7 8 9 10 do           j = ' expr $n \* $i '

         echo " $n x $i = $j "          i = ' expr $i + 1 ' done

Comments

Popular posts from this blog

python(BI)

Prac_8(AMP)