In this article, we would discuss how we can easily create PATH shortcuts in BASH. BASH – Bourne Again Shell, is a command line interpreter. Furthermore, if we talk of shell – in simple language, it allows us to execute commands.
Few articles back we discussed creating command shortcuts using alias – a built-in shell command – Create and use alias in Ubuntu.
This one is different from command shortcuts. Herein, we intend to have PATH with filename assigned to the variable.
Consider a scenario, wherein we have to enter a particular PATH/filename repeatedly in the shell. Although, nothing wrong with that. But, it hampers our productivity. We could have devoted time lost to other things and would have performed better.
In those cases, PATH shortcuts can really help. We understand with couple of examples.
Create PATH shortcuts in BASH
Let’s say we want to create a shortcut for /etc/hosts file. We don’t want to type the entire filename every now and then. Therefore, we store the entire PATH and filename in a variable. Just make sure that, the variable name shouldn’t correspond to any other variable used by the system.
Now, we need to the add the variable to the environment. This can be done using export command.
To verify if everything has gone the way we want them to be –
it should return with the output –
Use cat command-line utility to display the contents of the file –
Now, see the difference – we haven’t provided the complete file name. Just the variable name. But, the variable will be lost if we log out from the shell. To make the changes permanent, we need to append the ~/.bashrc configuration file.
To append, use a text editor like nano –
Thereafter, append the file with the following code containing the variable –
save and exit. To make changes in the current shell.
To verify if everything went as intended –
In conclusion, if the variable is already defined somewhere then issues may crop up. This will not be fruitful in those cases. Apart from that, it is great to have PATH – filename shortcuts to make things easier for us.