Source .profile using bash?
Solution 1
That script itself must be sourced for it to make changes to the current shell. If you run the script, a new instance of bash is started to interpret the commands in the script. This new instance cannot alter its parent, thus any aliases that are set in the script, dies with the script.
Solution 2
I'm way too late for this party but actually I was having exactly the same problem today. I came by to find a solution but what I found kept me thinking "this can't be the workaround to this".
So I went again to Terminator's options and the way I solved it was just by clicking a check-mark control inside the Terminator preferences. Just by checking the "Run command as a login shell" and then restarting Terminator, I was able to run "rails console" or "rails server" without having to source no file.
screenshot for the Terminator's preference window :
Related videos on Youtube
Chirag
Updated on September 18, 2022Comments
-
Chirag over 1 year
I am unable to source my
~/.profile
using a bash script.I tried:
source ~/.profile
By the way this is the script I am using
#!/bin/bash echo Enter the shortcut, or alias, you want to use: read SHORTTEXT echo Now enter what text you want it to replace: read LONGTEXT echo "alias $SHORTTEXT='$LONGTEXT'" >> ~/.profile echo "alias $SHORTTEXT='$LONGTEXT' was added to your profile.The alias will work after logoff/on"
-
geirha almost 12 yearsWhy do you want to source
~/.profile
from a script? That's seldom, if ever, any point in doing. -
geirha almost 12 yearsFirst off,
~/.profile
is the wrong place to put aliases, they should be in~/.bashrc
. Secondly, aliases don't work in scripts; you have to specifically enable aliases in scripts. Unless you source your script from an interactive shell, those alias settings will have no effect. -
Chirag almost 12 yearsCan you please elaborate why ~/.profile is a wrong place to put aliases. I read it somewhere on internet and it really works for me. Is there any specific diadvantage of doing so?
-
-
Chirag almost 12 yearsSo what to do ideally?
-
geirha almost 12 years@ChiragVora Either have the user source the script instead of running it, or make it a function (which must be put in
~/.bashrc
first). -
Chirag almost 12 yearsThanks for your help. I did exact what you described. It works fine.