Paths & Comments in Bash

Table of Contents

What is Path?

Absolute Path
Relative Path

Commands

Bash Comments

Single Line Comments
Multiline Comments
Method – 1
Method – 2

What is Path?

A path to a file is to determine the unique location o…


This content originally appeared on DEV Community and was authored by Jatin Sharma

Table of Contents

  • What is Path?
    • Absolute Path
    • Relative Path
  • Commands
  • Bash Comments
    • Single Line Comments
    • Multiline Comments
    • Method - 1
    • Method - 2

What is Path?

A path to a file is to determine the unique location of a file or directory in an OS filesystem. You can travel or change the location of the current directory through a terminal or command line.

In file system, there are two types of paths by which you can locate the directory or a file.

  • Absolute Path
  • Relative Path

Absolute Path

An Absolute Path is the full path of the file or directory from root to the file. An Absolute path of any directory always starts with a slash (/) representing the directory root.

/home/jatinsharma/Desktop/Bash 

Now if you are in the some directory x and you want to determine the absolute path of that you just run pwd command which is stands for Print work directory. It gives you the absolute path of the current directory as shown below-

pwd

Relative Path

The Relative Path of a file is its location relative to the current working directory. It never starts with a slash (/) or root. It begins with the current work directory.

Desktop/Bash 

Commands

  • cd . refers to the currect directory
  • cd .. moves the directory back one directory
  • cd ~ this send you to the /root directory
  • cd ../.. this sends you the back by two directory
  • pwd prints the absolute path of the current directory demo

Bash Comments

It does not matter which language you are using comments are one of the essential things. In our case, you can also create comments in the bash. There are two types of comments-

  • Single Line Comments
  • Multiline Comments

Single Line Comments

To write single line comment in bash, we have to use hash # symbol at the starting of the comment. Following is an example of Bash Script which contains single-line comments in between commands:

# single-line-comment.sh
# !/bin/bash

# This is a single-line comment in Bash Script.

echo "hello world"

# echo output, its also a single line comment

echo "hiii, good morning"

# This is another single line comment

Multiline Comments

In bash there are two ways to write multiline comments. You can use any of them according to your preference.

Method - 1

# multiline-comment.sh
#!/bin/bash

<<COMMENTS
    This is the first comment
    This is the second comment
    This is the example of multiline comments
    This is not going to print on screen
COMMENTS

echo "Hello World"

Method - 2

# multiline-comment.sh
#!/bin/bash

:'
This is the first comment
This is the second comment
This is also the example of multiline comments
'
echo "Hello World"

Wrapping up

In this article I've discussed about the Absolute and Relative paths and how you can use them and also how you can write the Single and Multiline comments in the bash script.


This content originally appeared on DEV Community and was authored by Jatin Sharma


Print Share Comment Cite Upload Translate Updates
APA

Jatin Sharma | Sciencx (2022-05-09T06:35:46+00:00) Paths & Comments in Bash. Retrieved from https://www.scien.cx/2022/05/09/paths-comments-in-bash/

MLA
" » Paths & Comments in Bash." Jatin Sharma | Sciencx - Monday May 9, 2022, https://www.scien.cx/2022/05/09/paths-comments-in-bash/
HARVARD
Jatin Sharma | Sciencx Monday May 9, 2022 » Paths & Comments in Bash., viewed ,<https://www.scien.cx/2022/05/09/paths-comments-in-bash/>
VANCOUVER
Jatin Sharma | Sciencx - » Paths & Comments in Bash. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/05/09/paths-comments-in-bash/
CHICAGO
" » Paths & Comments in Bash." Jatin Sharma | Sciencx - Accessed . https://www.scien.cx/2022/05/09/paths-comments-in-bash/
IEEE
" » Paths & Comments in Bash." Jatin Sharma | Sciencx [Online]. Available: https://www.scien.cx/2022/05/09/paths-comments-in-bash/. [Accessed: ]
rf:citation
» Paths & Comments in Bash | Jatin Sharma | Sciencx | https://www.scien.cx/2022/05/09/paths-comments-in-bash/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.