Showing posts from April 10, 2011

Shell Scripting - part 2

Command Line Arguments
Here we will discuss some more about command line arguments( values passed along with script like flags in commands)
and how they can be accessed in script

1)Name of the program
The name of the program is stored in variable '0'
So the value can be accessed as ${0}
e.g:- vi
echo ${0}
The output of the program will be like
2)All arguments passed along with script
All values passed to the script(command line arguments) will be stored in variable '@'
So the value can be accessed as ${@}
e.g:- vi
echo ${0}
If you execute the script with ou…

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 ca…

Basic Shell Scripting-step by step