2014-01-09

Shell script-defining static variable

Pranaam to all bhai ji _/\_
Today we will continue with shell script writing and we will study about echo command and defining static variable in shell script

lets talk about echo command :)

echo command to display text or value of variable

syntax
echo [options] [variables...]

here Option may be
  -n Do not output the trailing new line.
  -e Enable interpretation of the following backslash escaped characters in the strings
     like

     \b backspace
     \n new line

-e is required when we are using backslash escaped characters in our script with echo command else they wont be interpreted by shell

for example, i am writing 2 lines in script
1 line is without -e and
second with -e option


run shell script and see


script didnt considered \n as new line character and printed as it is on screen
so we can see what is the importance of -e with echo  command

Variables in shell script:-
in shell script we have system defined variables and user defined variables
system defined variables are those which is reserved for system(like $SHELL $HOME )

lets move and learn about user defined variables
user defined variable is one the important part of script because usr defined variable hold such value which is assigned by user
we can assign value to a variable using 2 method
one is during script coding(static)
second is during script execution(dynamic, when script is executing,it will ask to user for assigning values to variables )

first of all we will learn how to define variables during script coding(statically)
as i mentioned , those variables whose value is assigned during script coding and this value remain unchanged
how????
lets have an example :)

in shell script, for defining variable we write like this

variable_name=some_value
here
variable_name is the name of variable
and
some_value is the value of the variable which will be stored in that variable
like this

s=bash

here shell is the variable which store value 'bash' in it


for printing value stored in a variable, we have to echo that variable
put $ symbol before variable name in echo line
like this
echo $s
and it will echo  the value stored in 's' variable


Note:- if you are using value which has space in it, enclose that value in double quotes, else it will through error :P
like this

s="bash is a shell"
echo   $s

this is short intro how to define static variables in shell script :)
Thank you

Greetz to :- Guru ji Zero , code breaker ica, Aasim shaikh,Reborn, Raman kumar rana,INX_r0ot,Darkwolf indishell, Chinmay Pandya,L0rd Crus4d3r ,Silent poison India,Magnum sniper,Atul Dwivedi,ethicalnoob Indishell,Local root indishell,Irfninja indishell Hardeep bhai,Mannu,Viki and AR AR bhai ji <3
Share this post

0 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

© 2009 Start With Linux | Mannu Linux
Designed by cyb3r.gladiat0r
Posts RSSComments RSS
Back to top