3

To be clear im not looking for a workaround that will execute a change directory command on startup. I want to alter the $HOME env var so that tilde commands work and so that entering a 'cd' command will return me to that directory.

I am sure it is possible I am just not able to find the command.

I have tried setting it in my /etc/profile but it doesnt seem to work. I have tried about 4 different settings in there. The ones I can remember trying are:

$HOME = /directroy
$HOME = "/directroy"
setenv HOME /directory

I may be missing something simple but I'm unable to find a solution.

3
  • Actually I wonder more why HOME is not already set correctly when the shell starts. If you open a new tab in Terminal, what is the result of echo $HOME?
    – nohillside
    Jun 6, 2013 at 6:41
  • 1
    @patrix I probably should have been more descriptive. It is "correctly" set to my user's home directory. I would like it to be a different directory as all of my terminal use is based out of another directory.
    – Andrew
    Jun 6, 2013 at 16:22
  • 2
    I strongly recommend against doing that. The convention that $HOME points to your home directory is strongly embedded in Unix space and lot of shell scripts, perl scripts, binaries rely on that. You will get better results by defining something like MYROOT=/Users/andrew/base/of/all/things and then use $MYROOT where appropriate.
    – nohillside
    Jun 6, 2013 at 16:57

2 Answers 2

5

In bash (the default shell of Terminal on 10.8) the syntax:

HOME=/your/path
export HOME
1
  • This only worked for my current session. Opening a new terminal would have HOME reset back to its original value. Nov 23, 2018 at 12:09
0

Expanding on @patrix comment, change your $HOME/.bash_profile file to add the following lines:

MYROOT=/path/to/dir/you/want
export MYROOT
cd $MYROOT

This way you will get you will start your shell in /path/to/dir/you/want and using cd $MYROOT will bring you back there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .