My awl - SHELL - Variables

technonotes-hacker - Mar 3 - - Dev Community

Variables

  1. why we need ? A place in the memory in which the value is stored and can be used when you want.
  2. Its like an address
  3. Define the variable ? Where you want to store the value ? Defining the address --> variable_name=value
  4. You can store number & string value.
  5. variable_name -> No special character is allowed. only "_"
  6. If you are storing string values , it needs to be in "".
  7. How to retrieve ? $variable_name

Image description

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

Image description

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. Image description
  • *$ * 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.

Image description

Image description

$# *--> Total no of arguments used.
*
$@
--> Display all the arguments.

$? --> Exit status of the previous command.

Image description

Image description

$$ --> Process ID of the current shell

Image description

shift --> arguments gets shifted each time.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player