6

All over the internet you see this commands

alias hello='echo Hello' 

Yes, I know the above is a lame example, but it's beside the point. If I execute that, it works. But when I restart my computer, it is lost. Why? a bug with the alias command? Why would it only work until a restart is executed?

Thanks

Nadine
  • 777
  • 1
  • 11
  • 24

1 Answers1

17

You will need to write it into your ~/.bashrc like

echo "alias hello='echo hello'" >> ~/.bashrc

This appends the string to your .bashrc and will be read when you start a bash in xterm or even pure command line.

bash.d
  • 13,029
  • 3
  • 29
  • 42
  • Excellent, thanks. But what is the point of the Alias command if it doesn't remember anything? By itself, it seems a dumb command :/ – Nadine Aug 19 '13 at 10:37
  • 3
    You are welcome. It will be remembered as long as your bash-session is valid. This is why there is `.bashrc` to make your bash "remember" after power-off ;) – bash.d Aug 19 '13 at 10:38
  • So is ~/.profile and ~/.bash_profile just used to store variables? and ~/.bashrc for aliases? Like currently in mine, I use the export VAR=Var_value command to remember a var. – Nadine Aug 19 '13 at 10:42
  • Have a look at `~/.bashrc` using `less` or `cat`; there is usually some other stuff in there. You can put all `bash`-relevant stuff in there, like environment-variables or define scripts. – bash.d Aug 19 '13 at 10:44
  • There's nothing in mine (using OSX, that might be why). http://stackoverflow.com/questions/415403/whats-the-difference-between-bashrc-bash-profile-and-environment told me though. Thanks for your answer, no more re-typing alias commands :) – Nadine Aug 19 '13 at 11:01
  • 1
    @Nadine Yes, bash is not that important on OSX, as for example on Linux. Now you can spent these typed characters somewhere else :) – bash.d Aug 19 '13 at 11:12
  • this answer did not work any more in my MACBOOK AIR. – Ngoc Nam Apr 07 '21 at 15:37