0% found this document useful (0 votes)
13 views11 pages

Unit 1 LP

The document discusses the Vi/VIM text editor, highlighting its command and insert modes, and its popularity among programmers. It also covers shell responsibilities, including pipeline hookup, environment control, and the interpreted programming language of the shell, which allows for easier debugging but slower execution. Additionally, it explains shell variables, their types, and how to define, access, and unset them.

Uploaded by

rajsreerama.s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views11 pages

Unit 1 LP

The document discusses the Vi/VIM text editor, highlighting its command and insert modes, and its popularity among programmers. It also covers shell responsibilities, including pipeline hookup, environment control, and the interpreted programming language of the shell, which allows for easier debugging but slower execution. Additionally, it explains shell variables, their types, and how to define, access, and unset them.

Uploaded by

rajsreerama.s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Text editors (Contd.

)
1. Vi/VIM editor
Vim editor is one of the most used and powerful command-line based editor of
the Linux system. By default, it is supported by most Linux distros. It has enhanced
functionalities of the old Unix Vi editor. It is a user-friendly editor and provides the
same environment for all the Linux distros. It is also termed as programmer’s
editor because most programmers prefer Vi editor. Vi editor has some special
features such as Vi modes and syntax highlighting that makes it powerful than
other text editors. Generally, it has two modes:
Command Mode: The command mode allows us to perform actions on files. By
default, it starts in command mode. In this mode, all types of words are
considered as commands. We can execute commands in this mode.
Insert Mode: The insert mode allows to insert text on files. To switch from
command mode to insert mode, press the Esc key to exit from active mode and ‘I’
key.
To invoke the vi editor, execute the vi command with the file name as follows:

vi <file name>
Shell responsibilities (Contd.)
Pipeline Hookup
Just as the shell scans the command line looking for redirection
characters, it also looks for the pipe character |. For each such
character that it finds, it connects the standard output from the
command preceding the | to the standard input of the one following
the |. It then initiates execution of both programs.
So when you type

the shell finds the pipe symbol separating the


commands who and wc. It connects the standard output of the
former command to the standard input of the latter, and then
initiates execution of both commands.
Shell responsibilities (Contd.)

When the who command executes, it makes a list of who's logged in


and writes the results to standard output, unaware that this is not
going to the terminal but to another command instead.
When the wc command executes, it recognizes that no filename
was specified and counts the lines on standard input, unaware that
standard input is not coming from the terminal but from the output
of the who command.
Shell responsibilities (Contd.)
Environment Control
The shell provides certain commands that let you customize your
environment. Your environment includes your home directory, the
characters that the shell displays to prompt you to type in a
command, and a list of the directories to be searched whenever you
request that a program be executed.

Interpreted Programming Language


The shell has its own built-in programming language. This language
is interpreted, meaning that the shell analyzes each statement in the
language one line at a time and then executes it. This differs from
programming languages such as C and FORTRAN, in which the
programming statements are typically compiled into a machine-
executable form before they are executed.
Shell responsibilities (Contd.)
Programs developed in interpreted programming languages are
typically easier to debug and modify than compiled ones. However,
they usually take much longer to execute than their compiled
equivalents.
The shell programming language provides features you'd find in
most other programming languages. It has looping constructs,
decision-making statements, variables, and functions, and is
procedure-oriented. Modern shells based on the IEEE POSIX
standard have many other features including arrays, data typing, and
built-in arithmetic operations.
Shell variables
A variable is a character string to which we assign a value. The value
assigned could be a number, text, filename, device, or any other type
of data.
A variable is nothing more than a pointer to the actual data. The shell
enables you to create, assign, and delete variables.
Variable Names
The name of a variable can contain only letters (a to z or A to Z),
numbers ( 0 to 9) or the underscore character ( _).
By convention, Unix shell variables will have their names in
UPPERCASE.
The following examples are valid
variable names −
Shell variables (Contd.)
Defining Variables
Variables are defined as follows −
variable_name=variable_value
For example −
NAME="Zara Ali"
The above example defines the variable NAME and assigns the value
"Zara Ali" to it. Variables of this type are called scalar variables. A
scalar variable can hold only one value at a time.
Shell enables you to store any value you want in a
variable. For example −
Shell variables (Contd.)
Accessing Values
To access the value stored in a variable, prefix its name with the dollar
sign ($) −
For example, the following script will access the value of defined
variable NAME and print it on STDOUT −
Shell variables (Contd.)
Read-only Variables
Shell provides a way to mark variables as read-only by using the read-
only command. After a variable is marked read-only, its value cannot
be changed.
For example, the following script generates an error while trying to
change the value of NAME −
Shell variables (Contd.)
Unsetting Variables
Unsetting or deleting a variable directs the shell to remove the
variable from the list of variables that it tracks. Once you unset a
variable, you cannot access the stored value in the variable.
Following is the syntax to unset a defined variable using
the unset command −

The above command unsets the value of a defined variable. Here is a


simple example that demonstrates how the command works −

The above example does not print anything. You cannot use the
unset command to unset variables that are marked readonly.
Shell variables (Contd.)
Variable Types
When a shell is running, three main types of variables are present −
•Local Variables − A local variable is a variable that is present within
the current instance of the shell. It is not available to programs that
are started by the shell. They are set at the command prompt.
•Environment Variables − An environment variable is available to
any child process of the shell. Some programs need environment
variables in order to function correctly. Usually, a shell script defines
only those environment variables that are needed by the programs
that it runs.
•Shell Variables − A shell variable is a special variable that is set by
the shell and is required by the shell in order to function correctly.
Some of these variables are environment variables whereas others
are local variables.

You might also like