Saturday 26 September 2015

Shell pattern

Kernel is the core which is an entity that is in charge of handling users requests allowing them to access hardware resources and services provided by system.
And Shell is a program offering the user a simple interface enabling it to transmit its requests to the system kernel with commands addressed to the core.

Variable:

In shell, there are two types of variables:
• variables that are internal to the shell, which can only be used in the current shell and you can create as explained above;

• environment variables, which are used in the current shell as well as prospective sub-shells.

In shell script:
$? Return value of the last executed command
$# Argument count of the script/function
$0 Script/function name. Shell dependent
$n Value of the nth parameter of the script/function (1 <= n <= 9)
$@ List all the arguments without any substitution
$* List all the arguments, as one word
$$ Current shell PID
$! Last background started task PID


Some environment variables:

 $PATH ----List of directories where the shell is empowered to search the executable.
$LD_LIBRARY_PATH----List of directories where libraries loader is entitled to seed the necessary dynamic libraries the program.
$USER----Name of the current user.
$HOSTTYPE----System architecture.
$PS1----User prompt configuration.
$TERM----Current terminal type.
Use env command to list all the environment variable.

Regular expressions


Builtins
The builtins are commands integrated to the shell and executed by the shell itself.
To check whether a command is a builtin or not, we can use the builtin builtin.

Quoting
double quotes "
It is strongly recommended to use double quotes at the use of variable containing a string of characters.

simple quotes '
 The single quotes have the same behavior as double quotes, but they inhibit the expansion of variables.

Back-quotes `
They allow to run a command in a sub-shell.

Regular expressions

Regular expressions, called regexp or regex, are an essential support for many UNIX.
A regular expression is a pattern that describes a set of strings. Regular expressions are constructed as arithmetic: they use different operators to combine smaller expressions.

Basic regex
ABCD =~ ABCD    = match
abcd =~ ABCD     = mismatch
xyzABCDxyz =~  ABCD = match

The dot: represents one instance of any character.
AxB =~ A.B  =>match

Start ^ and end $: string. For example ^a means ”any string beginning with ’a’”; b$ means ”any string ending with ’b’”.

Alternative: The character |, preceded by a backslash \, represents an alternative between two elements.


Lists are shortcuts for alternatives: instead of writing a\|b\|c, we can write [abc].

If the first character of the list is ^, the meaning of the list is reversed and becomes ”all except one of the character list”:




No comments:

Post a Comment