I am trying to create a shell script that once run, adds a line of code to the end of .bashrc then reloads the terminal. This is the code i have written in my install.sh
function addbashaliases() {
echo 'if [ -f ~/aliases/.bash_aliases ]; then
. ~/aliases/.bash_aliases
fi' >> ~/.bashrc;
source ~/.bashrc
}
Nothing is happening. How should I write the code so that it runs and adds the text to the .bashrc file?
For the sake of clarity I prefer to append the information on the
.bashrc
file using thecat
command instead of theecho
. However, this should work also using yourecho
command.This said you should make sure that:
addbashaliases
function~/aliases/.bash_aliases
file exists (I would expect to have something more similar to~/.aliases/.bash_aliases
)You can check that the script has correctly run by checking the content of the ~/.bashrc file and printing some environment variable set on the
.bash_aliases
file after thesource
command.I am just correcting your script. As per your logic it should be like below.