Hello! In the last article as a part of the Getting Started series, we discussed the most commonly used Linux Commands. Now we are going to discuss about the basics of the development environment. This article helps in understanding about bash, bashrc and PATH variable and its various uses.

bash:

A Shell is something that acts as an interpreter between us (user) and the Operating system. When we want to navigate around the file system, execute programs or interact with external devices, we use the shell. Shell in turn interacts with the OS and performs operation we requested. BASh “Bourne Again Shell” is the most common form of shells for Linux.

.bashrc:

.bashrc is a shell script found in your home directory (for every user). Before your every session, this script is executed.

What is PATH variable?

Environment variable is a dynamic value used by operating systems and application software to determine information specific to the system.

PATH is basically an environment variable, specifying a set of directories where the OS should look for the executable programs. Whenever you launch a program from the Bash, the OS searches in the PATH variable. If the program cannot be found in these directories, you will get an error.

For example, You launch riscv64-unknown-elf-gcc from the bash. The OS will look for this executable inside all the directories specified in the PATH Variable. However if the executable is not found in the current directory and all the directories in the PATH, you will receive an error.

Note: To find the path use echo $PATH !

.bashrc and PATH variable:

Whenever you want to set an custom variable or add a directory to the PATH, Set it in bashrc. If you set it through terminal, it is set only for that particular session. When you set it through bashrc, it applies for every session.

SHAKTITOOLS=/path/to/shakti-tools
export PATH=$PATH:$SHAKTITOOLS/bin

The above lines will set up a variable called SHAKTITOOLS. Also it also adds the directory “$SHAKTITOOLS/bin” to the PATH variable.

After setting the PATH variable in bashrc, when you launch, riscv-unknown-elf-gcc, the executable which is a part of SHAKTI-TOOLS would be recognized.


One of the other coolest uses of bashrc is you can use it set up aliases. Take your most commonly used commands and set up an alias to it. so you can type the “alias” instead of the entire command during execution.

For example,

alias update="sudo apt-get update && sudo apt-get upgrade"

Instead of typing both the commands, you can just use “update“.

Note: After editing your bashrc, if you want to apply them immediately, run the command below.

source ~/.bashrc

However apart from single shorthand commands, you can also combine multiple commands into a single operation using BASh functions. They usually follow the below syntax,

Function name() {
Command 1
Command 2
}
mkcd() {
mkdir $1 #$1 is the first parameter
Cd $1
}

Now you can use just mkcd filename instead of using mkdir and cd.

bashrc” is an efficient and a highly customizable tool. When used right, it can increase your productivity by a whole lot! Do you want to learn more about SHAKTI? Click here!

This Post Has 2 Comments

  1. linux commands

    Greetings from Carolina! I’m bored at work so I decided to browse your site on my iphone during lunch break.

    I really like the info you present here and can’t
    wait to take a look when I get home. I’m amazed
    at how fast your blog loaded on my phone .. I’m not even using WIFI,
    just 3G .. Anyhow, amazing blog!

    1. Akshaya

      Hey Carolina,
      Thats so good to know! Thanks!

Leave a Reply