Variable and Comments | Shell Scripting

Variable and Comments | Shell Scripting

This is a multipart blog article series where I am going to explain the concepts of shell scripting and how to write a shell script in Linux, UNIX or Mac based systems. You can also follow this tutorial blog using windows but for that you have to install a bash from.

In this article we will see that how can we write comments and different types of variables and how to use them.

  1. Comments: Comments can be added by using # sign, the text written after this sign will be consider as comment.

  2. Variables:

    • Variables are container which stores some data inside them.
    • There are two types of variable system variable and “user defined variables”.
    • System variables are created and maintained by the LINUX or UNIX system itself. These variables are standard variables defined by the operating system. The standard convention is that they are written in capital case.
    • User defined variables are created and maintained by the user like us. Generally these variables are defined in lower case.
  3. System variables:
    • $BASH: This will give you the name of the shell you are using.
    • $BASH_VERSION: This will give you the version of the bash you are using.
    • $HOME: This will give the address of home directory.
    • $PWD: It stands for resent working directory; this will give us the address of present working directory.
    • These are more system variables but these are the most common one.
  4. User defined variables:
    • We can define a variable in the way <variable_name>=<value>. And we can call it like this echo $<variable_name>
    • Your variable name should not start with number, becasue shell will not consider it as a variable.

So this was all about variables and comments in shell. Hope you liked it and learned something new from it.

If you have any doubt, question, queries related to this topic or just want to share something with me, then please feel free to contact me.

📱 Contact Me

Twitter, LinkedIn, Telegram, Instagram,

📧 Write a mail

rahulmishra102000@gmail.com

GitHub, HackerRank