Variables in Bash
Variable :
- Variable is a container used to store data.
- Variable declaration in bash is similar to other programming language.
- Here the data type need not to be declared as in python.
- Three ways of declaring variable in Bash:
- Declaring variable inside the Bash script
- Getting input from the user.
- Getting input through parameter.
- Declaring Variable inside the bash script:
- variable_name="variable"
- Note : Don't leave space.
- Getting input from the user:
- The "read" command is used to get input in bash script.
- read followed by the variable_name.
- read <variable_name>
- Getting input through parameter:
- It is possible by decalring the variable_name to $1. Here the $1 indicate the first parameter.
- It can be made for any number.
- While running,After "bash <file_name> is consider as parameter 1"
- Example : bash <file_name> 1 2 3 ....
No comments:
Post a Comment