Wednesday, May 18, 2022

Bash Scripting 4

 Bash scripting


Using our own variable:
  • In the terminal we can create our own variable.
  • if we call the variable it reflects the value.

  • This cannot be used inside a bash script. Since it is a parent variable and the child function that is inside script cannot use it.
  • To use a variable which is declared outside can be done by using export command.
  • Command : export <variable_name>
  • Before using export command:

  • After exporting the variable:

  • But,These variable will be removed once we logout.
  • To make a variable which is permanently available.We can edit the ".bashrc" file in home directory.
  • If a file name start with a period(".").This means the file is hidden.
  • The hidden file will not be visible on "ls" command.
  • To display hidden files "ls -al" can be used .
  • The "al " is nothing but list all command.

  • Edit the script with any file editot like nano.
  • nano .bashrc
  • At last ,add "export <variable_name> = <variable_value>"
  • Restart the machine.
  • So we can can use the variable outside. 

Using command output has variable Value:
  • The command output can also be used has variable value.
  • The comand is <variable_name>=$(command)






No comments:

Post a Comment

Google Cybersecurity Professional Certificate

    Google Cybersecurity Professional Certification 🔒 Google Cybersecurity Professional Certification: A Journey Unveiled! 🔒 Hey Folks! 🌟...