1

I just want to add a path in ~/.bashrc as:

export PATH="$Home/gg/gamit/bin:$Home/gg/kf/bin:$Home/gg/com:$PATH"

But when I am using echo $PATH is showing it as:

/gg/gamit/bin:/gg/kf/bin:/gg/com:/home/sandypuja/bin:/home/sandypuja/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin 

But I need it to look like

/home/sandypuja/gg/gamit/bin:/home/sandypuja/gg/kf/bin:/home/sandypuja/gg/com:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin 

where sandypuja is my system name.

How can I rectify this?

  • 2
    Linux is case-sensitive: $HOME is a recognised variable - $Home is not – steeldriver Nov 23 '19 at 12:58
  • $Home will be an empty string indeed. – vanadium Nov 23 '19 at 13:02
2

Shell and environment variables are case-sensitive (as steeldriver says). Home is not the same variable as HOME. The HOME environment variable contains a path to your home directory. The Home variable typically does not exist; there is nothing special about the name Home.

When a variable is not defined, performing parameter expansion on it yields the empty string (as vanadium alludes to), which is what you're seeing.

Replacing $Home with $HOME should fix the problem:

export PATH="$HOME/gg/gamit/bin:$HOME/gg/kf/bin:$HOME/gg/com:$PATH"

Note that you should not typically set environment variables, especially PATH, in ~/.bashrc, because:

  1. That file is only sourced by bash shells, so they will be unavailable in a number of important contexts including graphical programs not started from bash.
  2. That file is sourced by all interactive bash shells, so when you start one interactive bash shell from another, the child shell will have the path modified again. So the directory name will be prepended multiple times. The performance impact is negligible but it can be quite confusing when you're inspecting the variable's value.

If you want to set or modify an environment variable like PATH by editing a file that is sourced by shells, you can use ~/.profile rather than ~/.bashrc.

(I say "especially PATH" because it is very common to include the old value of PATH in the new value, as you are doing, and when this is done in ~/.bashrc it creates the annoyance described in #2 above.)

| improve this answer | |
  • Thanks, it worked for me, Thanks A lot – sandeep gupta Nov 25 '19 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.