Variable Assignment & Expansion
Explore how to assign values to variables in Bash without type declaration and use parameter expansion to retrieve and modify variable content. Learn best practices such as avoiding spaces in assignments, using quotes for strings with spaces, and differentiating shell and environment variables to write clear and effective Bash scripts.
We'll cover the following...
How to set a variable?
Variables usually come in handy when you need to store or retieve something during program execution. To assign a value to a variable we use “=” operator. In Bash, you do not need to declare the type of a variable unlike C++ and JAVA. Which means you can assign any value to a variable whether it is a number, a character or a string of characters.
Some variables are preset by the system but we can set our own variables as well. The syntax to assign value to a variable is given below:
Variable Expansion
We use "$" sign to give a reference to a variable. This technique is often referred ...