best linux shell scripting course

Best way to learn Linux & Shell scripting | Introduction CH-2

Chapter:2 Learn about use of pwd command

To know, the path or the location at which you’re currently in the system. pwd command is used in Linux. Executing the pwd command in the terminal will return the path of the directory as a result. 

> pwd
/home/mtroview/test

Great!! Now you know the use of pwd in Linux. Let’s discuss the use of pwd in shell scripting.

In some scenarios, we change the directory in the script. To save/store the starting location in the script to use it later in code we use pwd. Sharing the example to store/save the working/starting directory path in a variable in the script.

current_directory=$(pwd)

or

current_directory=`pwd`

Using any of one above method, you can save the path of the directory in the script & can use it later as per requirement.

You can print the value of the current_directory variable using the echo command that we have learned in chapter 1. Please execute and try it on your computer. It will boost your confidence.

Chapter:3 In next chapter will learn about ls command

1 thought on “Best way to learn Linux & Shell scripting | Introduction CH-2”

  1. Pingback: Best way to learn Linux & Shell scripting | Introduction CH-1 - MtroView

Leave a Comment

Your email address will not be published. Required fields are marked *