College of Informatics and Virtual
Education
CP 211: Linux Administration
Shell Scripting
Vi Editor
There are a number text editors in Linux.
If you are using a GUI, you can run gedit, which is fairly intuitive for editing text. There’s also a simple
text editor you can run from the shell terminal which is called nano.
However, most Linux shell users will use either vi (vim) or emacs to edit text files. The advantage of vi
or emacs over a graphical editor is that you can use it from any shell, a character terminal, or a
character-based connection over a telnet.
Vi Command Modes
vi has two modes:
The command mode and
The insert mode.
When you are in command mode, letters of the keyboard will be interpreted as commands.
When you are in insert mode the same letters of the keyboard will type or edit text.
vi always starts out in command mode. When you wish to move between the two modes, keep these things in mind.
You can type i to enter the insert mode.
If you wish to leave insert mode and return to the command mode, hit the ESC key. If you're not sure where you are, hit ESC a
couple of times and that should put you back in command mode.
Basic Commands
Basic Commands
Basic Commands ...
Basic Commands ...
Basic Commands ...
Basic Commands ...
Basic Commands ...
Basic Commands ...
Linux System Architecture
Variables
This echoes "one two three" to the
screen. Note the use of double quotes
This would echo "Hello There!" to enclosing the string.
the console display
Variables
To display special characters use the sysmbol \. Eg. The presentation \\ would output \
Surrounding anything within single quotes causes it to be treated as literal text that is it will
be passed on exactly as intended, this can be useful for sending command sequences to
other files in order to create new scripts because the text between the single quotes will
remain untouched. For example:
This would cause "msg="Hello World!" to be echoed and
redirected to the file hello, "echo $msg" would then be
echoed and redirected to the file hello but this time
appended to the end.
Important internal bash variables
Passing parameters to scripts
Bash Conditional Expressions
Bash Conditional Expressions
Bash Conditional Expressions
Reading from standard input
Exit status
Branching with if
Branching with if