Week 4
In week 4 we were thoroughly introduced to The Shell.
First we started with some definitions:
blank - A space or tab.
Word- A sequence of characters considered as a single unit by the shell. Also known as a token.
Name- A word consisting only of alphanumeric characters and underscores, and beginning with an alphabetic character or an underscore. Also referred to as an identifier.
Metacharacter -A character that, when unquoted, separates words. One of the following: | & ; ( ) < > space tab
control operator - A token that performs a control function. It is one of the following symbols: || & && ; ;; ( ) |
Reserved words are words that have a special meaning to the shell.
A shell script is a file that contains commands to be executed by the shell. Making a File Executable – use chmod: $ chmod +x scriptname
Read (command) = is used to accept the user input and store the input in variable.
If a word begins with a tilde character (`~'), all of the characters preceding the first slash (or all characters, if there is no slash) are treated as a possible login name.
Command substitution allows the output of a command to replace the command name. There are two forms:
$(command) or `command
Built-in Shell Variables are very useful and important:
$#
|
Number of command-line arguments.
|
$-
|
Options currently in effect (arguments supplied to sh or to set).
|
$?
|
Exit value of last executed command.
|
$$
|
Process number of current process.
|
$!
|
Process number of last background command.
|
$0
|
First word; that is, command name.
|
$n
|
Individual arguments on command line (positional parameters). The Bourne shell allows only nine parameters to be referenced directly (n = 1-9); the Korn shell allows n to be greater than 9 if specified as ${n}.
|
$*
|
All arguments on command line ("$1 $2...").
|
"$@"
|
All arguments on command line, individually quoted ("$1" "$2" ...).
|
|
|
The shift command – promotes each of the command line arguments. $2 becomes $1, the third becomes the second, etc.
The set command - sets the values of the command line arguments
Control Flow Commands – they include control structures:
-
Simple two-way branching If statement
-
Multiple branching Case statement
-
For, While and Until statements
Dostları ilə paylaş: |