Shell script-Defineing dynamic variable

Pranaam to all bhai ji _/\_
In our last tutorial we discussed about static variable in shell script, today we will go through how to define dynamic variable in shell script.
Dynamic variable is one whose value is not definite. dynamic variable value is decided during program execution .
For example , we are coding a script which ask to us for input name and then print that value on screen.
we will define a variable in script whose value will be decided at script run time.
lets  start with user defined dynamic variables :)
for defining a dynamic variable whose value can be define at script run time by user , we have to do following  thing in our shell script
read is the function which will accept the input from user during shell script execution and will store that input in a variable
line of code for accepting input and storing it to variable is
Syntax :-
read  variable

like, i want to store value to a variable 'r', line will be
read  r
 when i will run script, script execution will pause at the line where read  r is  written and will ask to user for input . once user define input and press enter, script execution will continue.
have a look at this code

echo "pranaam bhai ji _/\_ , glad to see you here  "
echo -e "please enter your name , i am waiting for input \n"
read  r

echo "the name you entered is  $r"

save this code in a file and run it

running shell script and script paused its execution when read r line came for execution (read  r)

i entered the input and press enter.
read function took input value and stored in variable 'r' and
echo "the name you entered is  $r" line  printed the value that got store in variable r after the text ' the name you entered is'

this is just a short intro to how to use user defined dynamic 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,Hackuin ,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


:) :-) :)) =)) :( :-( :(( :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