I have been trying to add optional aliases to my .bash_aliases
file, but I have run into an issue with optionally adding aliases. So far it seems that the aliases get added no matter what the if statement seems to be evaluating to true.
Here is an example of what I am trying to do:
alias gh="history | grep"
alias python="python3"
# personal computer aliases
if [ ${COMPUTER_TYPE} = "personal" ]
then
alias hibernate="sudo systemctl hibernate"
fi
Here is the variable being set in .bashrc
(setting it in .profile
does not seem to do anything either):
export COMPUTER_TYPE=work
Echoing the variable:
$ echo $COMPUTER_TYPE
work
Any idea what I am doing wrong here? If I had to guess, the .bash_aliases
file is not a bash file that gets treated as one, but that seems unlikely. Thanks for the help!
Edit: I see that my question may be misleading as the example used was a personal computer, but the problem is that when I run the alias on a work computer it still adds all aliases. I have since updated the example to use work
instead of personal
.