What’s the difference between storing aliases and environment variables?
Aliases are simply a new way that we give to commands so we can use them on our own terms, for example, let’s say that we would like to always start from the desktop and check location and see a list of files, but to do so we forcefully need to write
cd ~/Desktop; pwd; ls every time. but with the alias we can simply say:
alias 2strt = cd ~/Desktop; pwd; ls
Now, after it is sourced we just need to run
2strt and it will direct us to Desktop, let us know that we are there and show the files and directories there.
On the other hand, environment variables are just like variables in programming languages, simply keywords that store data, in this case, usually sensitive data that we may want to keep offline.
Let’s say I have a route that I don’t want people to see me type if they are passing by, so I will create an environment variable for it in .bash_profile:
And so, after sourcing, I could say
cd $MY_ROUTE and I will be taken to the location I need to work at.
So now we might find a little clearer where the differences are between aliases and environment variables, yes, they are both like keywords, but an alias holds a reference to a command and an environment variable just withholds data.