Variables
- why we need ? A place in the memory in which the value is stored and can be used when you want.
- Its like an address
- Define the variable ? Where you want to store the value ? Defining the address --> variable_name=value
- You can store number & string value.
- variable_name -> No special character is allowed. only "_"
- If you are storing string values , it needs to be in "".
- How to retrieve ? $variable_name
Local Variable : It can be overridden.
Env Variable : which is available inside the script and also in parent shell.i.e Terminal = Parent Shell , every time you run a script it creates a child shell --> You need to remember this. --> EXPORT
If the variable is created in parent shell , all the child shell can receive it or access it. Those are called Env Variables.
If the variable created in child it wont be available in parent shell.
Special Variables
Command Line Arguments :
- $0 name of the script.
- Take max of 9 values.
- *$ * followed by something --> it will print something. that's the literal meaning.
- There is a concept called " NEGATION" --> you are forcing the linux not to consider the $. Eg., \$0 --> Hello Linux DONT CONSIDER AS $ and print , you just ignore or negate it.
$# *--> Total no of arguments used.
*$@ --> Display all the arguments.
$? --> Exit status of the previous command.
$$ --> Process ID of the current shell
shift --> arguments gets shifted each time.
Top comments (0)