1

Everytime after I restart the machine, "source ~/.bash_profile" has to be executed first in order to use "python" as an alias for "python3". Is there a solution for this problem?

I have the following lines in my ~/.bash_profile:

# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH=/opt/python35/bin/:$PATH
alias python="python3"
export PATH

Thanks in advance!

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Cindy
  • 489
  • 1
  • 4
  • 11
  • An `alias` doesn't belong in `.bash_profile`; they belong in `.bashrc` instead. – Charles Duffy Feb 16 '16 at 16:42
  • ...also, PATH is *already* exported before your `.bash_profile` is started, so there's no reason at all to export it again, let alone to do so twice. – Charles Duffy Feb 16 '16 at 16:43
  • isn't there an /etc/environment file on linux systems for stuff like this? – Uncle Iroh Feb 16 '16 at 16:48
  • @UncleIroh, depends on the specific distro, not a guarantee. And aliases aren't part of the *environment*. Environment can be evaluated only once, at login time (and then simply inherited by future processes started within that session), whereas aliases need to be introduced with every new shell instance. This is exactly why `.bash_profile` is useful for one thing but not the other. – Charles Duffy Feb 16 '16 at 16:56
  • @UncleIroh, ...now, there **are** exported functions -- you could define an environment variable that bash interprets as a `python3` function -- but that's getting into advanced usage, and the details vary by version (the shellshock fix changed the naming protocol for exported functions in incompatible ways, and some of the interim fixes made by distro vendors at the time were incompatible with both the original *and* the new conventions). – Charles Duffy Feb 16 '16 at 16:57

0 Answers0