• Join over 1.2 million students every month
  • Accelerate your learning by 29%
  • Unlimited access from just £6.99 per month
Page
  1. 1
    1
  2. 2
    2
  3. 3
    3
  4. 4
    4
  5. 5
    5
  6. 6
    6
  7. 7
    7
  8. 8
    8
  9. 9
    9
  10. 10
    10
  11. 11
    11
  12. 12
    12
  13. 13
    13
  14. 14
    14
  15. 15
    15
  16. 16
    16
  17. 17
    17
  18. 18
    18
  19. 19
    19
  20. 20
    20
  21. 21
    21

Unix Shell Programming

Extracts from this document...

Introduction

(2009 – 2010)

image00.png


No.

Programs

Page

1

PROGRAM TO ADD AND MULTIPLY TWO NUMBERS

3

2

PROGRAM TO CALCULATE THE FACTORIAL OF A NUMBER

4

3

PROGRAM TO CHECK A NUMBER WHEATHER IT IS A PRIME NUMBER OR NOT

5

4

PROGRAM TO CHECK A NUMBER WHEATHER IT IS AN ARMSTRONG NUMBER OR NOT

6

5

PROGRAM TO CHECK A NAME WHEATHER IT IS A PALINDROME OR NOT

7

6

PROGRAM TO READ A NUMBER AND PRINT THE NUMBER IN WORDS

8-9

7

PROGRAM TO PRINT THE FIBONACCI SERIES

10

8

PROGRAM TO FIND THE QUOTIENT AND THE REMAINDER BETWEEN TWO NUMBERS WITHOUT USING ‘/’ AND ‘%’ OPERATOR

11

9

PROGRAM TO FIND THE GREATEST NUMBER AMONG THE THREE NUMBERS

12

10

PROGRAM TO INPUT A FEW NUMBER IN AN ARRAY AND DISPLAY THE NUMBERS WHICH ARE GREATER THAN THE AVERAGE OF ALL THE NUMBERS

13

11

PROGRAM TO PRINT A WORD IN ALL IT’S PROBABLE OR POSSIBLE WAYS

14

12

PROGRAM TO CALCULATE THE AGE

15

13

PROGRAM TO REVERSE AN INTEGER NUMBER

16

14

PROGRAM TO FIND THE THE DIVISION ON AVERAGE MARKS

17

15

PROGRAM TO FIND THE EXE FILES OF A PWD

18

16

PROGRAM TO SHOW THE CONTENTS OF A FILE IF IT IS READABLE

19

17

PROGRAM TO COUNT THE WRITABLE FILES OF A PWD

20

18

PROGRAM TO READ A FILENAME AND SHOW THE CONTENTS OF A READABLE FILE IF THE NAME IS OF A DIRECTORY FILE OR SHOW THE CONTENTS IF IT IS A NORMAL FILE OTHERWISE IF IT IS A BLOCK SPECIAL OR CHARACTER SPECIAL FILE THEN SHOW THAT IT IS A SPECIAL FILE

21

...read more.

Middle

y = ‘ expr $name|cut –c $i ‘

z = ‘ expr $name|cut –c $j ‘

if = [ $i!= $z ]

then

flag = 1

fi

i = ‘ expr $name|cut –c $i ‘

done

if [$flag –eq 1]

then

 echo The name is a Palindrome.

else

echo The name is not a Palindrome.

fi

OUTPUT

Enter a name: KANAK

The name is a Palindrome.


-:PROGRAM TO READ A NUMBER AND PRINT THE NUMBER IN WORDS:-

SOURCE CODE

echo Enter a number:

read num

ct = ‘ expr $num|wc –c ‘

ct = ‘ expr $ct -1 ‘

i = 1

p = 2

while [ $i –le $ct]

do

if [ $p –eq $ct ]

then

case $num in

10) echo Ten ;;

11) echo Eleven ;;

12) echo Twelve;;

13) echo Thirteen ;;

14) echo Fourteen ;;

15) echo Fifteen ;;

16) echo Sixteen ;;

17) echo Seventeen ;;

18) echo Eighteen ;;

19) echo Nineteen ;;

*) p = 1

esac

if [ $p –eq 1 ]

then

c = ‘ echo $num|cut –c $i ‘

case $c in

2) 1= ‘Twenty’ ;;

2) 1= ‘Twenty’ ;;

2) 1= ‘Twenty’ ;;

2) 1= ‘Twenty’ ;;

2) 1= ‘Twenty’ ;;

2) 1= ‘Twenty’ ;;

2) 1= ‘Twenty’ ;;

2) 1= ‘Twenty’ ;;

2) 1= ‘Twenty’ ;;

esac

p = 3

fi

if [ $num –le 19]

then

exit

fi

c = ‘ echo $num|cut –c 2 ‘

if [ $c –eq 0 ]

then

exit

fi

else

c = ’ echo $num|cut –c $ct ‘

case $c in

s= ‘Zero’ ;;

s= ‘One’ ;;

s= ‘Two’ ;;

s= ‘Three’ ;;

s= ‘Four’ ;;

s= ‘Five’ ;;

s= ‘Six’ ;;

s= ‘Seven’ ;;

s= ‘Eight’ ;;

s= ‘Nine’ ;;

esac

fi

p = 1

I = ‘expr $i + 1’

done

if [ $ct –eq 2 ]

then

z = ‘echo $1 $s’

echo $z

else

echo $s

fi

OUTPUT

Enter a number: 75

Seventy Five


-:PROGRAM TO PRINT THE FIBONACCI SERIES:-

SOURCE CODE

echo  Mention the range that you want to see

read n

i=1

s=1

l=0

while[ $i –le $n]

do

if [ $i –eq 1]

then

                echo 0

...read more.

Conclusion

One of the file is Numsummul


-:PROGRAM TO SHOW THE CONTENTS OF A FILE IF IT IS READABLE:-

SOURCE CODE

echo Enter a filename:

read  file

if[-r $file]

then

echo The content of the file is –

cat $file

else

        echo The file has no read permission.

fi

OUTPUT

Enter a filename: exiefiles

The file has no read permission.

Enter a filename: exefiles

The content of the file is –

for i in `ls`

do

        if[-x $i]

        then

                echo One of the file is $i

fi

done


-:PROGRAM TO COUNT THE WRITABLE FILES OF A PWD:-

SOURCE CODE

for i in `ls`

do

        if[-w $i]

        then

                ct= `expr $ct + 1`

fi

done

echo The numbers of write permitted files are $ct

OUTPUT

The numbers of write permitted files are 6


-:PROGRAM TO READ A FILENAME AND SHOW THE CONTENTS OF A READABLE FILE IF THE NAME IS OF A DIRECTORY FILE OR SHOW THE CONTENTS IF IT IS A NORMAL FILE OTHERWISE IF IT IS A BLOCK SPECIAL OR CHARACTER SPECIAL FILE THEN SHOW THAT IT IS A SPECIAL FILE:-

SOURCE CODE

echo Enter a filename:

read file

if[-d $file]

then

        m=1

elif[-f $file]

then

        m=2

else

        m=3

fi

case $m in

  1. Cd $file

for I in `ls`

do

        if[-r $i]

then

        echo $i

fi

done

cd

;;

  1. Cat $file

mv  $file Newone

;;

  1. Echo The file is a special file::

esac

OUTPUT

Enter a filename: writable.sh

for i in `ls`

do

        if[-w $i]

        then

                ct= `expr $ct + 1`

fi

done

echo The numbers of write permitted files are $ct

Page  of

...read more.

This student written piece of work is one of many that can be found in our University Degree Computer Science section.

Found what you're looking for?

  • Start learning 29% faster today
  • 150,000+ documents available
  • Just £6.99 a month

Not the one? Search for your essay title...
  • Join over 1.2 million students every month
  • Accelerate your learning by 29%
  • Unlimited access from just £6.99 per month

See related essaysSee related essays

Related University Degree Computer Science essays

  1. Marked by a teacher

    UK Copyright and File Sharing

    5 star(s)

    The bill is centralised around requiring Internet Service Providers (ISP's) to take more of a responsibility in taking action against file sharers. The government will require ISPs to issue offenders with numerous letters, and "if this proves insufficient, they could be prevented from going online by the internet service provider" (Khan, 2009).

  2. Traffic Light Simulation and Machine Code Program.

    Cursor A flashing symbol that indicates position within text. Alternatively the mouse cursor indicates the mouse position. Special purpose cursors are used in some software. Data tables These store numbers, text or pointers to other data objects. It is easier to look after data in a table than data scattered throughout a program.

  1. Applying AI to Finance. The Symbolic and Sub-Symbolic approaches.

    * Preparation and analysis of reports As mentioned above ES are very good at financial analysis field. CoverStory is an expert system developed by IRI to tackle the problem of too much data. Ocean Spray has been a development partner and first client.

  2. Entering Compiling and Running C Programs ...

    { int I,N; int s=0; clrscr(); printf("Enter an integer N: \n"); scanf("%d",&N); i=1; do { s=s+i; i=i+1; }while(i<=N); printf("The Sum=%d\n",s); getch(); } Output of the program In the above program user enters 34 instead of N,so the sum is 1+2+...........+34=595.

  1. Table of contents

    AI requires either complex algorithms or a lot of time for machine learning, to become intelligent. Collective intelligence has features more like that of a Distributed system: o Scalability o Fail-safe & Graceful degradation o Local autonomy (no centralized authority)

  2. What is Six Sigma?

    It analyzes the capability of the process and aims at stabilizing it by reducing or eliminating variations. The key concepts are as follows: * Defects: failing to deliver what customer needs * Variation: what the customer sees and feels * Critical to quality: attributes most important to the customer *

  1. Avon, which began its operations in 1886, is a global manufacturer and marketer of ...

    a system for managing the company's sales representatives and a customer relationship management system. In the case study, it stated the requirements of the new systems where how it will roughly be like. They are focused on greater utilization of the Internet for the business.

  2. Java Network Programming UsingSmtp &amp;amp;#150; Report/Overview.

    Extended SMTP or ESMTP was created to get around this problem. Implementation of the client application import java.awt.*; import java.io.*; import java.net.*; import java.util.*; class SMTPInputStream { private InputStream is=null; SMTPInputStream(Socket s) throws IOException { is = s.getInputStream(); } String ReadFromStream()

  • Over 160,000 pieces
    of student written work
  • Annotated by
    experienced teachers
  • Ideas and feedback to
    improve your own work