2

When you type cd, it basically does the same thing as cd ~. Why?

I'm wondering if it's just a hard-coded behavior or if bash is expanding the command or something.

1
  • 2
    man cd: If no directory operand is given and the HOME environment variable is set to a non-empty value, the cd utility shall behave as if the directory named in the HOME environment variable was specified as the directory operand. Commented May 8, 2013 at 19:01

1 Answer 1

4

That is the POSIX specified behaviour. Not bash-specific.

6
  • 5
    And it's not only POSIX shells. All shells do, even non-POSIX and non-Bourne ones like csh, rc, fish... cd is one of the few builtins that is common to every shell since Unix version 7. Commented May 8, 2013 at 19:55
  • @StephaneChazelas are there actually any non-POSIX shells still around? besides DOS (and probably powershell)?
    – strugee
    Commented May 9, 2013 at 0:23
  • 1
    @strugee. As I said, csh (and its derivative tcsh), rc (and it's derivatives like es or akanga), fish, and a few esoteric ones. CMD.EXE, COMMAND.COM and POWERSHELL.EXE are not Unix shells AFAIK. tcsh and fish are well alive. zsh is POSIX-like but not POSIX compliant and is the Unix shell used by most people who actually /use/ a shell (as their main interface to the system). Commented May 9, 2013 at 7:14
  • @StephaneChazelas yeah, i was being more general than "unix shell" when i said shell. anyway, thanks!
    – strugee
    Commented May 9, 2013 at 17:42
  • Doesn't do that under Windows... Bites me every time. Commented Jan 28, 2019 at 15:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.