Chapter 1: Bash Home

Bash Home — or more precisely, what “$HOME” means in Bash, and also the famous ~ (tilde) that people use all the time.

Think of your computer like a big apartment building. Every person (every user) gets their own private apartment. That apartment is called your home directory.

In Bash (and in Linux/macOS in general), your personal apartment has two very common names/ways to refer to it:

  1. $HOME → the official, polite name (an environment variable)
  2. ~ → the short nickname (a special Bash shortcut)

Both almost always point to the exact same place — usually something like /home/webliance on your system in Hyderabad.

Let me explain it like we’re sitting together looking at your terminal.

1. What exactly is the “home directory”?

When you log in to Linux / Ubuntu / macOS / Git Bash / WSL etc., the system says:

“Welcome back Webliance! Go sit in your room → /home/webliance”

This folder (/home/your-username) is special because:

  • You have full permission to create/delete/change anything inside it
  • Most of your personal files live here (Documents, Downloads, Desktop, Pictures…)
  • Hidden configuration files for programs live here (.bashrc, .gitconfig, .ssh/, etc.)
  • When you open a new terminal → it automatically starts inside your home directory

Try this right now in your terminal:

Bash

You will probably see something like:

text

or on macOS maybe

text

or in Git Bash on Windows

text

That path = your home directory.

2. How Bash gives you two easy ways to say “my home”

Way 1: The variable → $HOME

$HOME is a normal environment variable (like a sticky note the system wrote for you).

Try these:

Bash

→ /home/webliance (or whatever your actual path is)

Bash

→ My important files are in /home/webliance/Documents

Bash

→ takes you home and shows the path

Very safe and clear — especially inside scripts!

Way 2: The shortcut → ~ (tilde key — usually left of 1 key)

Bash has a special rule: whenever it sees ~ (not inside quotes), it replaces it with your home path automatically.

Try:

Bash

→ same as echo $HOME

Bash

→ /home/webliance/Desktop

Bash

→ shows files in your Downloads folder (without typing full path)

Super short and convenient when typing commands by hand!

3. Important differences between $HOME and ~

Feature ~ (tilde) $HOME
Type Shell expansion (Bash magic) Normal environment variable
Works inside double quotes? No → “today ~” prints “today ~” Yes → “today $HOME” works
Works inside single quotes? No → ‘go to ~’ prints ‘go to ~’ No → ‘go to $HOME’ prints literally
Works in scripts? Usually yes, but can be tricky Always safe and recommended
Can refer to other users? Yes → ~rahul (home of user rahul) No (only your own home)
What if HOME is unset? Bash still knows from /etc/passwd Empty or error
Best for typing fast? Yes No (longer)
Best for writing scripts? Okay, but many people prefer $HOME Yes — clearer & more portable

Quick examples:

Bash

4. Real-life examples you will use every day

Bash

5. Small quiz for you (try in terminal!)

  1. What does this print? echo ~root
  2. What does this print? echo “~webliance”
  3. Which is better in a script that many people will use? ~/bin or $HOME/bin ?

(Answers: 1. /root 2. ~webliance (no expansion) 3. Usually $HOME/bin is safer)

Summary – like a good teacher would say

  • ~ = quick nickname for your home (great when typing)
  • $HOME = official name, always reliable (great in scripts + strings)
  • Both take you to your personal room in the computer → /home/webliance (most likely)
  • When in doubt in scripts → use $HOME — it’s boring but bulletproof 😄

Got it? Now open your terminal and play with these for 2 minutes:

Bash

Tell me what you see — or ask next: “Teacher, explain ~/.bashrc” or “difference between / and ~” or anything!

Keep practicing — Bash will feel like home very soon! 🏠🐧

You may also like...

Leave a Reply

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