The question is in the title. I could not find anything on google, so im hoping someone here can explain this to me.
I am using debian 6.0.5 and the shell assigned to the executing user in the /etc/passwd file is /bin/bash
So, simply writing cd ~ works and brings me to the users home directory.
test -d "~/some_dir" returns false in an if statement ( some_dir exsits )
Edit:
Sorry I should’ve been more clear as of why I was writing /bin/bash cd ~ instead of cd ~: I am writing a bash script with #!/bin/bash and the above mentioned if statement ends up in the false clause.
The options for any command line are expanded before the command is run, even for internal commands. Whatever shell you’re using to run
/bin/bash cd ~is presumably interpreting the tilde literally rather than a special character that expands to your home directory.As a test, try creating a directory by that name and see if the error goes away.
Note that the
cdcommand needs to be done within your running shell to be useful. When you change the working directory of a sub-shell, and then the sub-shell exits, you’ll find yourself back where you started.UPDATE:
From within a bash script, you should be able to use the
$HOMEenvironment variable, which should consistently contain your home directory. I’m not aware what conditions would cause tilde expansion to fail, but I’ve always used$HOME.Also, when determining whether you can change into a particular directory, you have the option of being explicit and returning useful status:
Or, you can just try the CD and look at its results.
Detailed error reports are handy, but if you don’t need them, keeping your code small has advantages as well.