Tuesday, April 12, 2011

Shell Scripting - part 1

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

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} for retrieving the value assigned to VAR


b)On the fly
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

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


# Dispaly the value of a variable

echo ${VAR}


No comments:

Post a Comment

LVM thin provisioning - file system usage and pool usage dosn't match

When I was demonstrating LVM thin provisioning to new batch of campus hires ; they pointed out an important mismatch between thin pool usag...