Vi editor
viis generally considered the de facto standard in Unix
editors because −
It's usually available on all the flavours of Unix system.
Its implementations are very similar across the board.
It requires very few resources.
It is more user-friendly than other editors such as
the ed or the ex.
3.
Vi editor
Tocreate a new file testfile if it already does not exist in the current working directory −
$vi testfile
The above command will generate the following output −
|
~
~
~
~
~
~
~
~
~
~
~
~
"testfile" [New File]
A tilde represents an unused line. If a line does not begin with a tilde and appears to be
blank, there is a space, tab, newline, or some other non-viewable character present.
4.
The Unix
Architecture
Kerneland shell
The kernel interacts with the machine’s hardware and the
shell with the user.
The kernel is the core of the operating system - a collection
of routines mostly written in C.
The kernel is loaded into memory when the system is
booted and communicates directly with the hardware.
5.
What exactly
is a“shell”?
The shell acts as an interface between the user and the
kernel.
The shell is a command line interpreter(CLI).
User commands are often entered on a command line
interface that is provided by a “shell”.
The shell is a program that reads the user commands,
evaluates it, and then prints the result.
For evaluating the command, the shell may execute other
commands, or pass them to the ‘kernel’.
Bourne shell If you are using a Bourne-type shell, the $
−
character is the default prompt.
C shell If you are using a C-type shell, the % character is the
−
default prompt.
The most popular shells are: bash, tcsh,csh, and korn.
Shell commands are case sensitive.
Shell variables
Theshell supports variables that are useful in both the
command line and shell script.
Eg. $ x=10 No $ required for assignment
$ echo $x but needed for evaluation
A variable can also be assigned the value of another variable
Eg. $ y=$x
$ echo $y
All shell variables are initialized to null string by default.
x = A null string
A variable can be removed with unset and protected from
reassignment by readonly.
unset x x is now undefined
readonly x x can’t be reassigned
8.
Effect of
quoting and
escaping
message=Youdidn ’t enter the filename
Message= “You didn’t enter the filename”
$ echo The average pay is $1000
The average pay is $1000
$ echo ‘The average pay is $1000’
The average pay is $1000
$ echo “ The PATH is $PATH and the current directory is pwd”
The path is /bin:usr/bin: and the current directory is /home/a/b
$ echo The average pay is $1000
The average pay is 000 $1 belongs to a set of parameter “positional
parameters”
9.
Where to use
shell
variables
Setting Pathnames – if a pathname is used several times
in a script, we should assign it to a variable
$ progs = ‘/home/a/c_progs’
$ cd $progs ; pwd pwd – print working directory
/home/a/c_progs
Using Command Substitution
$ mydir = “pwd” ; echo $mydir
/home/a/c_progs
Concatenating Variables and Strings
base=foo ; ext=.c Two assignments in a line
file=$base$ext or file=$(base)$ext
cc -o $base $file. Creates executable foo from foo.c