Laynetworks  
Web laynetworks.com Google
Home | Site Map | Tell a friends
Journal of Management
Management Tutorials
Download
Tutorials
History
Computer Science
Networking
OS - Linux and Unix
Source Code
Script & Languages
Protocols
Glossary
IGNOU
Quiz
About Us
Contact Us
Feedback
 
Sign up for our Email Newsletter
 
Get Paid for Your Tech Turorials / Tips

 

 

Home > Source Code > Shell Script
Page : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Shell Script
 

Question 1. a : To Count number of character, words, & blank in a givent text

Clear

echo " Enter the String"

read str

echo $str > str.txt

len = 'echo $str | wc -c'

len = 'expr $len -1'

c= 0 , w = 0 , s = 0 , i = 1

echo " Length of string = $len"

w = 'echo $str | wc - w'

c = 'echo $str | wc -c'

 

while [ i -le $ len ]

do

st = 'cut - c$I str.txt'

if ["str" = " "] then

s = 'expr $s + 1'

fi

i = 'expr $i + 1

done

echo "Character = $c"

echo "Words = $w"

echo "Spaces = $s"

Question: 1.b : Write an algorithm/project to generate first prime numbers.

clear
no=1
r=0
while[$no -le 100]
do
t=0
i=1
while[$i -le $no]
do
rs='expr $no %$i'
if[$r -eq 0]
then
t='expr $i+1'
fi
i='expr $i+1'
done
if[$t -eq 2]
then
echo $no
fi
no='expr $no +1'
done

Algorithms

Step 1: START

Step 2: INPUT a positive number N to generate the

first N primenumbers.

Step 3: If N=1, then Print the number 2 and STOP.

Step 4: If N>1, then Print the first two prime numbers

2 and 3.

Step 5: Assign the value 2 to variable noprime and

value 4 tovariable num.

Step 6: If noprime=N, then goto Step-12.

Step 7: Assign value 2 to variable I.

Step 8: Divide the variable num by 2 and store in the

variable NUM1.

Step 9: Calculate the remainder of num divided by I

and store in variable number.

Step 10:If number=0, then increment num by 1 and goto

Step-7.

Step 11:If I=NUM1, then increment num by 1, noprime by

1,Print the value of num and goto Step-6.

Step 12:Increment the value of I by 1 and goto Step-8.

Step 13: STOP.

Question:1.C : Write a shell program to accept more than one month

#!/bin/sh
argstr=$@
argc=$#
year = `echo $argstr | awk '{print \$'$argc'`
cnt = 1
while { $cnt -lt $argc }
do
tmp = `echo $argstr | awk '{print \$'cnt '}'`
cal @tmp $year
cnt ='expr $cnt + 1'
done

TOP
 
Page : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19