I have an "installer" script that installs a couple scripts and a directory for them. This works as expected. In the middle of my script I also have an alias I inject into the local .bashrc so that the script can be called from the commandline:
echo -e "..........Adding Alias"
echo "alias Change=~/ChangeTool/Change" >> .bashrc
echo -e "..............Recompiling environment"
. ~/.bashrc
I can confirm it does show up in my .bashrc when I run the installer. However, if I rm -rf
my script directory, remove the line from (and recompile with . ./.bashrc
) my .bashrc, and reinstall, I get "Change command not found".
I then thought to myself "o.k., I'll try again." so I remove the line and recompile bashrc myself. I more
.bashrc and it's no longer there. Out of curiosity I tried the Change command and it worked.
Is there just some weird delay with installing aliases?
Edit: Here is the output on fresh install:
PSTSAUTO@MUXALRM:~$ ./installer.sh
Installing [ ASR9K CHANGE TOOL ]
..........Targeting /home/PSTSAUTO/
..........Getting raw tarball
..............Extracting the tarball
..........Adding Alias
..............Recompiling environment
..........Install Complete.
PSTSAUTO@MUXALRM:~$ Change
Change: command not found
PSTSAUTO@MUXALRM:~$ grep "Change" .bashrc
alias Change=~/ChangeTool/Change
PSTSAUTO@MUXALRM:~$
So it's there but it doesn't work. As stated in code snippet above I did try to source with the .
command.
. ~/.bashrc
orsource ~/.bashrc
? Please add new information directly to your question ([edit]), do not use comments. – dessert Jul 30 '19 at 16:23.bashrc
file in your script for the terminal which runs the script, aren’t you? This is exactly what OP there was trying to do as well, and the answer explains nicely why that can’t work. – dessert Jul 30 '19 at 17:39.bashrc
only in the environment of your script, not outside. It's the same issue as why(export var=bla); echo $var
prints nothing. The duplicate is correct. – pLumo Jul 30 '19 at 17:45.bashrc
in the parent shell from within the subshell, the best you can do is open a new terminal tab/window with your script, but with all the different terminal emulators that’s a non-trivial task. – dessert Jul 30 '19 at 18:03.bashrc
as planned and also define it back to your parent shell at the same time? – WinEunuuchs2Unix Jul 31 '19 at 01:21