Working of an Alias

The alias keyword replaces the command with the string which might be sets of commands or functions. The alias is defined in the ~/.bashrc or ~/.bash_profile. These files are loaded in the shell environment and thus the commands listed in the alias are also been loaded and ready to be executed. Thus, the alias work with the BASH configuration.

After the aliases or command maps have been loaded, the user can interact and enter the commands. If the command in the alias is executed the BASH interpreter replaces the command alias with the string of commands and hence the desired functioning of the alias or command is achieved.

We’ll see how to create a BASH Alias in the next section.

Bash Scripting – Working of Alias

BASH Alias is a shortcut to run commands using some mapping. It is a way to create some shortcut commands for repetitive and multiple tasks. We create an alias in a BASH environment in specified files. We can also incorporate BASH functions, variables, etc to make the Alias more programmatic and flexible.

Similar Reads

What is a BASH Alias?

A BASH Alias is a map of commands with the sets of commands or functions that can be used as a shortcut in the command line for a BASH environment. Bash Alias allows to aggregate multiple functions into a single command and also it avoids repetitive or large commands into a simple shortcut command. BASH Alias is a map of shortcut command with the sets of commands which are stored in a file called either .bash_profile or .bashrc with a specific syntax. The aliases can also be combined with the BASH syntax and semantics to make the shortcuts more customizable and flexible....

Working of an Alias

The alias keyword replaces the command with the string which might be sets of commands or functions. The alias is defined in the ~/.bashrc or ~/.bash_profile. These files are loaded in the shell environment and thus the commands listed in the alias are also been loaded and ready to be executed. Thus, the alias work with the BASH configuration....

How to create an Alias?

To create an alias, we need to create a file called bash_profile or bashrc. This file needs to be in the root directory and should be hidden to avoid mishandling of its contents.  Inside of this file, we create an alias which is basically a map of commands and the sets of commands/functions to be executed as a shortcut....

Difference between single and double quotes

The single and double quotes used in the alias statements have some importance and need to be used as per requirement. We use double quotes to expand the value of the variable in BASH i.e to actually parse in the value of the variable name. If we just use single quotation marks, the variable’s value is not displayed and just the variable-name is parsed as it is....

Structure of an Alias

After creating an alias we can understand the structure of an alias in a bit of depth.  As discussed earlier, we have three parts in creating an alias:...