Navigation Menu

Currently the navigation bar is not functioning. Use the Blog Archive or the Google Custom Search to find content.
Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Saturday, 22 June 2013

Shell scripting using general-purpose utilities - Menu driven program

Given below is a menu driven shell script which will print the following menu and execute the given task to display result on standard output.
MENU
1 Display calendar of current month
2 Display today’s date and time
3 Display usernames those are currently logged in the system
4 Display current directory
5 Display your terminal number
6 Exit

Friday, 14 June 2013

Shell script to display prime numbers

Bash script to display prime numbers.

Links that you may find important :

https://en.wikipedia.org/wiki/Prime_number
http://en.wikipedia.org/wiki/List_of_prime_numbers
http://en.wikipedia.org/wiki/2_%28number%29

Code :
echo 'Enter no'
read x
n=2
while [ $n -le $x ]
do
i=2
count=1

while [ $i -lt $n ]
do
if [ `expr $n % $i` -eq 0 ]
then
count=0
break
fi
i=`expr $i + 1`
done

if [ $count -eq 1 ]
then
echo "$n is Prime"
fi

n=`expr $n + 1`
done
Output :
2 is Prime
3 is Prime
5 is Prime
7 is Prime
Note : Leave a comment if you feel the program is incorrect and/or has errors and/or if the program and its output don't match. Please report about broken links.