Experiment 1 and 2
Experiment 1 and 2
Experiment 1 and 2
A Shell provides you with an interface to the Unix system. It gathers input from you and
executes programs based on that input. When a program finishes executing, it displays that
program's output.
Shell is an environment in which we can run our commands, programs, and shell scripts.
There are different flavors of a shell, just as there are different flavors of operating systems.
Each flavor of shell has its own set of recognized commands and functions.
Shell Prompt
The prompt, $, which is called the command prompt, is issued by the shell. While the
prompt is displayed, you can type a command.
Shell reads your input after you press Enter. It determines the command you want executed
by looking at the first word of your input. A word is an unbroken set of characters. Spaces
and tabs separate words.
Following is a simple example of the date command, which displays the current
date and time −
$date
Thu Jun 25 08:30:19 MST 2009
You can customize your command prompt using the environment variable PS1 explained in
the Environment tutorial.
Shell Types
● C shell (csh)
The original Unix shell was written in the mid-1970s by Stephen R. Bourne while he was at
the AT&T Bell Labs in New Jersey.
Bourne shell was the first shell to appear on Unix systems, thus it is referred to as "the shell".
Bourne shell is usually installed as /bin/sh on most versions of Unix. For this reason, it is the
shell of choice for writing scripts that can be used on different versions of Unix.
In this chapter, we are going to cover most of the Shell concepts that are based on the Borne
Shell.
Shell Scripts
The basic concept of a shell script is a list of commands, which are listed in the order of
execution. A good shell script will have comments, preceded by # sign, describing the steps.
There are conditional tests, such as value A is greater than value B, loops allowing us to go
through massive amounts of data, files to read and store data, and variables to read and store
data, and the script may include functions
In Unix-like operating systems, the chmod command is used to change the access
mode of a file. The name is an abbreviation of change mode.
Syntax :
chmod [reference][operator][mode] file...
The references are used to distinguish the users to whom the permissions apply
i.e. they are list of letters that specifies whom to give permissions. The references are
represented by one or more of the following letters:
Reference Clas Description
s
u own file's owner
er
g grou users who are members ofthe file's group
p
o othe users who are neither the file's owner nor members of the file's
rs group
a all All three of the above, same as ugo
The operator is used to specify how the modes of a file should be adjusted. The following operators
are accepted:
Operator Description
AIM:
To write a program to find whether a number is even or odd .
ALGORITHM:
PROGRAM
AIM :
To write a program to find biggest in two numbers.
ALGORITHM :
PROGRAM:
OUTPUT:
Enter The Two Number:
23 67
B is Big.
RESULT:
AIM:
To find a factorial of a number using shell script.
ALGORITHM:
PROGRAM:
fact=1
OUTPUT:
Enter a number :
5
The factorial is 120
RESULT:
Thus the program has been executed successfully.
Exp no-2.4LEAP YEAR
AIM :
Write a program to find the given year is leap year or not.
ALGORITHM:
PROGRAM:
OUTPUT :
Enter the year: 2023
RESULT: