2

I am trying to understand exporting paths in Bash, and someone had told me that /bin is not the same as ~/bin. What is the difference between the two?

  • 2
    One is a user directory, the other a system one... – jasonwryan Oct 31 '16 at 20:25
  • Also look at man bash, then search for TILDE EXPANSION. – Hack Saw Oct 31 '16 at 20:44
4

/bin always refers to the "bin" off of the root directory "/"
In Bash, ~ refers to the users home directory.
thus ~/bin refers to bin off of the user's home directory.

If the user's home is /users/cazs, then ~/bin will be /users/cazs/bin

~ seems to work in the sh shell and its myriad of derivations, including bash, which is what you asked about.

  • It's important to note that this is a shell feature, and not always available. – Hack Saw Oct 31 '16 at 20:42
  • 1
    Also, ~bob/bin would refer to something like /users/bob/bin. – Hack Saw Oct 31 '16 at 20:43
  • @HackSaw, which shell doesn't support ~? – MikeP Oct 31 '16 at 20:46
  • 2
    Most shells that I have used support it. Python doesn't, out of the box. You have to import os.path, and perform an explicit expansion. In general programming languages don't support it, save in libraries. – Hack Saw Oct 31 '16 at 20:48
  • 1
    @HackSaw, thanks. I was interpreting that some shells don't support it. It is good to note that it is a feature of command line interface (shell), like sh, bash, zsh, csh, tcsh, etc. – MikeP Oct 31 '16 at 21:00
0

~/bin refers to the bin directory in the current user's home directory. It is equivalent to $HOME/bin. If the current user's home directory is /home/jack, then ~/bin refers to /home/jack/bin.

/bin is an absolute path, its meaning is unambiguous.

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.