Today I've learned: Changing Shell Prompt Name/PATH importance 
(Environment variables)

Today I've learned: Changing Shell Prompt Name/PATH importance (Environment variables)

Prompts in Kali

Usually terminal in Kali looks like this

(username@hostname)-[current_directory] #

When you work as a root you see:

(root@kali)-[current_directory] #

Environment variable which is used to change the prompt

There’s a PS1 Environment variable which is responsible for names in the shell. By default it changes the username of the Shell prompt. For example:

(root@kali)-[/home] # PS1="Powerful friend #"
Powerful friend #

It’s a nice functionality when you have multiple terminals. Keep in mind that it is valid only for the session. Of course we could do the export PS1 to make it permanent.

PS1 placeholders

It has few options that can be changed (by default it changes the name):

  1. \u - The name of the current user

  2. \h - The hostname

  3. \w - The base name of the current working directory

PATH

PATH is one of the most important variables. It holds the directories in which the terminal will look for the commands that you enter. For example cd, ls, pwd and so on.

You can see the content of PATH variable by writing:

echo $PATH

Keep in mind that we write $PATH and not PATH.

$ symbol is very important. It means that we ask for the content of the variable.

New tool

For example you download a new tool from Github. You want to use it in the terminal often. You’ll have to change your terminal directory to the folder where the tool is located. Here’s where adding to the PATH variable comes in.

For example:

Your tool is stored in this directory → /root/amazingtool . To use it everywhere you can add to the PATH variable by doing so:

PATH=$PATH:/root/amazingtool

Important:

Keep in mind that we use $PATH. We append the new value.

Congratulations, now you can use your amazingtool everywhere in the system, because PATH will know where to search. You can check it again by writing:

echo $PATH

Of course try not to add too many directories to the PATH variable. It’ll slow your system down.

User-Defined Variable

We can create our own variables with names that we’d like. It’s useful when you have long terminal commands or you just want to have some extra “features” to flex about. Hehe.

For example let’s create a new variable called CYBRBLOG.

CYBRBLOG="Hacking is very cool"

And now let’s call it using echo and content symbol - $:

echo $CYBRBLOG
Hacking is very cool

Final thoughts

  • Environment variables are indeed very interesting part.

  • You can change the behavior of your system by changing those variables.

  • PATH is really important part

  • It’s very important to use $(content) symbol when for example adding a new directory to the PATH variable.

  • It’s cool that you can create your own variables

UPCOMING

Upcoming section is - Bash scripting.

I’m really excited about it. I already made one basic script to turn off my Kali laptop when finished learning.

cat first-script

#! /bin/bash

# This is my first script

echo "Hello, my friend, your system will shutdown. Bye!"
sleep 3
echo "Sleep well :)"
sleep 1
shutdown -h now

I’ll execute it using:

bash first-script

See ya later

CREDITS

I’m learning using this book:

Linux Basics For Hackers by OCCUPYTHEWEB (MASTER OTP)