Shell Script Assignment
Shell Script Assignment
18100BTIT03068
Assignment - 2
Audience-
1.
AYUSH NEEKHRA
18100BTIT03068
Philosophy-
Shell script programming has a bit of a bad press amongst some Unix
systems administrators. This is normally because of one of two things:
Not much, you may consider; the OS has to load up the /bin/grep
executable, which is a reasonably small 75600 bytes on my system,
open a pipe in memory for the transfer, load and run the /bin/cat
executable, which is an even smaller 9528 bytes on my system, attach
it to the input of the pipe, and let it run.
2.
AYUSH NEEKHRA
18100BTIT03068
A First Script-
For our first shell script, we'll just write a script which says "Hello
World". We will then try to get more out of a Hello World program than
any other tutorial you've ever read :-)
Create a file (first.sh) as follows:
First.sh
#!/bin/sh
# This is a comment!
echo Hello World
# This is a comment, too!
The first line tells Unix that the file is to be executed by /bin/sh. This is
the standard location of the Bourne shell on just about every Unix
system. If you're using GNU/Linux, /bin/sh is normally a symbolic link
to bash (or, more recently, dash).
The second line begins with a special symbol: #. This marks the line as
a comment, and it is ignored completely by the shell.
The only exception is when the very first line of the file starts with #! -
as ours does. This is a special directive which Unix treats specially. It
means that even if you are using csh, ksh, or anything else as your
interactive shell, that what follows should be interpreted by the Bourne
shell.
Similarly, a Perl script may start with the line #!/usr/bin/perl to tell your
interactive shell that the program which follows should be executed by
perl. For Bourne shell programming, we shall stick to #!/bin/sh.
now run chmod 755 first.sh to make the text file executable, and run
./first.sh.
Your screen should then look like this:
3.
AYUSH NEEKHRA
18100BTIT03068
You will probably have expected that! You could even just run:
C shell − If you are using a C-type shell the % character is the default
prompt.
C shell (csh)
TENEX/TOPS C shell (tcsh)
4.
AYUSH NEEKHRA
18100BTIT03068
The commands and syntax of the shell script are the same as that entered
at the command line. Because of this, there is no need to switch to a
completely different syntax.
It is much faster to write a code in shell script than in other programming
languages. This also means that the program is easier to create and files
required can be selected easily.
Shell script can also be used to provide linkage for already existing
programs.
Shell scripting can be used by users that are not experts to modify and
tailor the behaviour of their programs according to their requirements.
5.
AYUSH NEEKHRA
18100BTIT03068
6.
AYUSH NEEKHRA
18100BTIT03068
7.