Shell Scripting - part 1

The echo command
------------------
The easiest command in shell script
used for display text

e.g:-
echo "Hello world"

Variables in script
--------------------
variables are used for storing values
It may be pe-defined or the value will be assigned on the fly (On execution of script)

The variable manipulation in scripting
VAR=value

${VAR} for retrieving the value assigned to VAR


a)Pre-defined
e.g:-
VAR=10

b)On the fly
e.g:-
VAR=`expr ${i} + 1`

In example (a) the variabe VAR is assigned a value of 10
The value of VAR will be 10 through out the execution life of script(unless that variable is not alterd by another assignment)

In example (b)the variable VAR assigned a value that depend on the value of 'i' (another variable)
We will split the example to understand two command

expr ${i} + 1
and
VAR=


i) evaluat the expression ${i} + 1
ii) Assign the result to VAR

Using the echo command we can display the value assigned to a variable

e.g:- Write a script that having a variable VAR and assign a value 10 to it
Display the value of VAR in terminal
---------------------------------------------------------------------

#!/bin/bash

#
# Dispaly the value of a variable

VAR=10
echo ${VAR}

---------------------------------------------------------------------

Comments

Popular posts from this blog

How to Configure Squid with Mysql DB authentication

Linux OS backup and Restoration using ReaR – Relax & Recover

How to Configure YUM in RHEL6