Shell Script Programing Guide For Beginners
Shell Script Programing Guide For Beginners
Shell Script Programing Guide For BeginnersShell Script Programing Guide For Beginners |
Variables in shell scripting
Variable is a place in memory where you can store your data like strings/texts and numbers in shell scripting. As the name suggest variable it is not fixed its value can be changed depending on the information passed to the program.
Rules and conventions to create variable in shell scripting
- the variable name should start with the character or underscore.
This is a valid variable-
_name="my name is ABC"
This is also a valid variable -
name="my name is ABC" - You can't start the variable name with a numeric value at the beginning.
Name1=" My name is abc " is valid variable and
1name="My name is abc" is an invalid variable. - Variables are case sensitive in shell scripting.
name="first"
NAME="last"
Bash interpreter will treat them differently. Bash interpreter differentiates between upper-case and lower-case. - Comma's and blank spaces are not allowed.
Declaring variable in shell scripting
hello="hello viewers"
That's it. Now the variable hello is holding the string "hello viewers "
That's it. Now the variable hello is holding the string "hello viewers "
Accessing variables.
Note You can put the semicolon after the variables and statements.It is optional.
Save this file and make it executable and run.
Save this file and make it executable and run.
#variable declaration name="Welcome viewers" number=56 #accessing/printing variable #variables are accessed theought $ sign. echo $name echo $number;
- The first statement is a comment we discussed that in our previous article.
- In our second statement, we declared a variable name="Welcome viewers"; Variable name is storing value, welcome viewers.
- Last 2 statements are printing name and number variables on the output screen.
Also Check: Beginners Ethical Hacking Course
So above are the Shell Script Programing Guide For Beginners. Hope you like this article, keep on sharing with others too. Also, share your experience with us in a comment box below.
Post a Comment