What's shell script and the role of Environment variables with example

What's shell script

     The command interpreter is the interface between the user and the operating system.

     Shell script is a program that is based on Linux bash command to manipulate the functionality of your server . it's based on bash command (Linux command) also you can used the environment variable that will facilitate detection like path, home user ...

     In this example we see the role of the use the environment variable and command "pwd" we can also make this little program as a command.


the beginning and end of each shell script program

     To start your program you mast insert #!/bash/sh or #!/bash/bash
the "#!", is the name of a program which should be used to interpret the contents of the file and "exit 0" for exit program.


Condition

     Like any program also in shell script you can use the condition

 
To show a example https://github.com/boujeh/reseau.sh/blob/master/reseau.sh

the function


For example go to https://github.com/boujeh/distribution.sh/blob/master/distribution.sh

Environment variables

     Environment variables are one way to influence the behavior of software on your system . For example, the environment variable " LANG" determines the language that the software uses to communicate with the user .
Environment variables
Meaning
To View Variable Value Type
BASH_VERSION
Holds the version of this instance of bash.
echo $BASH_VERSION
HOSTNAME
The name of the your computer or server
echo $HOSTNAME
CDPATH
The search path for the cd command
echo $CDPATH
HOME
The home directory of the current user.
echo $HOME
PATH
The search path for commands. It is a colon-separated list of directories in which the shell looks for commands.
echo $PATH
SHELL
Set path to login shell.
echo $SHELL
DISPLAY
Set X display name
echo $DISPLAY export DISPLAY=:0.1
EDITOR
Set name of default text editor.
export EDITOR=/usr/bin/vim
TERM
Your login terminal type.
echo $TERM export TERM=vt100
UID
the user id.
echo $UID
DATE
the actual date.
date=`date +%d/%m/%y-%h%m` echo $date
$0
the name of program.
echo $0
$1,$2 ... $n
if you need read the argument with $1 you can show the first argument the second with $2 ...
echo $1
$#
if you need to know the number of argument.
echo $#
$*
To show all argument.
echo $*
OSTYPE
To detect the type of your os.
echo $OSTYPE

How executed shell scripting

     In the first you mast change the permission of your file example.sh

after that you have two methods
First method
    Like a simple program


second method
    Like a command but you mast copy in /usr/bin. With this method you will lunch you program when you need it you just write her name













Share on Google Plus

About Unknown

I am a cloud engineering student, I am interested in system and network admnistration. I am looking for an intership in order to get my engineer diploma, the internship I am looking for would preferably be of 6 up to 10 months long counting from december 2015.

    Blogger Comment
    Facebook Comment

0 commentaires:

Post a Comment