I want to run some scripts at system startup, so in ~/.profile file, I've added:

alias workspace="cd $WORKSPACE"

So I want this "workspace" alias to be available after the startup. Maybe it's not the right place to define these variables.

  • You might want to look into zsh's named directories. If you export workspace=~/Development/workspace, you can just just refer to the path as ~workspace; e.g. cd ~workspace – Michael Mrozek May 21 '10 at 5:41
  • @Mich I just got into a habit. I always vote to close and comment on it. This is for the benefit of low rep users(especially if the op is low rep) since they can not see the votes to close – Earlz May 21 '10 at 5:44
  • 1
    @pocoa: you do not state the kind of "startup" you are refering too. $SHELL startup? windowmanager startup? some other program startup? system startup? – akira May 21 '10 at 6:22

Perhaps you wanted to export WORKSPACE?

export WORKSPACE="~/Development/workspace"

You should be able to run 'set' and see the value of $WORKSPACE as it is - it is set, but not an environment variable because you did not export it. AFAIK, your alias will only be available in the top-level shell. You would place the alias in .bashrc or thereabouts to make it available in sub-shells too. (See §6.2 'Bash Startup Files' of the Bash manual for more information. Also, check that there isn't a .bash_login or .bash_profile file in your home directory; one of those would be used in preference to - not as well as - the .profile.)

One other possibility - you are not configured to use Bash or Korn shell. I rate that unlikely, but not completely out of the question. The C shell family uses .login and .cshrc files instead.

  • So how would you do that? I know I can add aliases with typing on command line. But I don't want to do that every time, I want to automate it. – pocoa May 21 '10 at 5:41
  • Yes, .bash_login and .bash_profile does not exists. – pocoa May 21 '10 at 5:55
  • Aliases can't exported. There's no need to export the variable in this case if it's not needed in the environments of children of the shell in which it's defined. Some people export every variable they create, but this can cause problems with unexpected results due to name collisions or uninitialized variables in scripts. – Paused until further notice. May 21 '10 at 7:59
  • @Dennis: AFAICT (and certainly as I intended), I said nothing about the alias being exported or exportable. You are right that not every variable needs to be exported; again, I did not say that they should all be exported. It depends on whether @pocoa has any use for the variable other than in the alias. My suspicion is that it might be generally useful as an exported variable, but that is not inevitably the case. – Jonathan Leffler May 21 '10 at 23:53
  • Sorry if I was unclear. I meant to supplement what you said, not correct it. Also, if someone wants functionality similar to an alias, but to have it available in child processes, in Bash functions can be exported. – Paused until further notice. May 22 '10 at 1:39

So What is your question exactly? Did you mean alias "workspace" is not available when you login to the unix box?

  • Yes. I want to type "workspace" and access to my workspace folder. – pocoa May 21 '10 at 5:39
  • Did you mean when you type "workspace" when you login, it does not take you to the appropriate folder? Have you tried putting it as alias workspace="cd ~/Development/workspace" – Kunal May 21 '10 at 5:43
  • @Kunal: In command line? I don't want to type it every time. – pocoa May 21 '10 at 5:53

I moved to:


it works now.


As a general rule, if you want to set an environment variable, you should use export in .profile, as others already said. You could also set it simply in .bashrc, but it will be a waste of memory (not that it matters much, just as a principle of things). As for aliases, you should set them in every shell, so that should go to .bashrc. Or even better, to .alias, which is by default sourced by .bashrc (in Ubuntu at least, but probably in other distros, too).

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.