Bash Profiles: Quick Tips to Make Life Easier

Bash Profiles: Quick Tips to Make Life EasierJustin WuBlockedUnblockFollowFollowingJun 11https://i.



jpgIf you are using Apple’s macOS, the default login shell that you use is Bourne-Again SHell or BASH for short.

BASH is a command language interpreter that is essentially used to read commands and run other programs.

Therefore, unless you were to change the shell your OS is running on, any command you run in your terminal is utilizing BASH.

Image Source: https://www.



jpgNow that we’ve given a basic explanation of BASH is, it’s time to get to the core of what we want to discuss: BASH profiles.

BASH profiles are essentially shortcuts that we can create through aliases and shell functions using custom commands.

While they aren’t required, they can help improve efficiency dependent on the shortcuts you create.

Setting Up Your BASH ProfileThe first order of business involves actually setting up your BASH profile.

For the purposes of this article, we are going to focus on setting up a persistent BASH profile.

The setup (setup URL is linked for those who would like to read up) itself is actually quite simple:Step 1.

Make sure you are in your home folder first using the command:cd ~/Step 2.

The next step is to create the actual file itself using the command:touch .

bash_profileStep 3.

The last step is to edit the actual file itself using the command:open .

bash_profileThis command will open your BASH profile file in your default text editor.

The default starting code that comes along with your BASH profile upon creationThere are two methods declaring these shortcuts, either via your terminal or persisting them in the physical file itself to be accessed as needed.

For the purposes of this article, we are going to focus on persistence.

BASH AliasesIn a nutshell, aliases are used primarily to create usable shortcuts that you can type directly into your terminal.

Similar to how you would set up a variable, aliases will set up the name of your custom command equal to some built-in function that BASH supports.

Custom aliases I created on my own BASH profileA pet peeve of mine is when I want to access files from a different directory without having to open a new terminal, often times using the command ‘cd .

’ can be time-consuming and inefficient.

In this example, I created an alias ‘.

2’ which will ‘cd’ up 2 directories, likewise with the alias ‘.


Aliases can also be used to set shortcuts if you constantly make typos.

Something as simple as:alias cd.

=’cd .

’In this example, if you use the command ‘cd .

’ a lot and mistakenly type in ‘cd.

’ instead, this shortcut can help you achieve the same result without having to retype the command.

BASH FunctionsShell functions work similarly to aliases but are more intuitive in how they are able to chain commands.

You can declare functions one of two ways,function function_name { commands }ORfunction_name () { commands }Within the functions themselves, you can utilize loops and conditionals to achieve whatever shortcut you’re trying to create.

Source Code: https://unix.


com/questions/97920/how-to-cd-automatically-after-git-clone/97958As an avid user of GitHub, often times I find it a hassle to have to clone a repository and then manually ‘cd’ into it.

Inside my BASH profile, I coded in a BASH function I found via the Unix StackExchange to create a function ‘git’.

What this function essentially does is:Check the command proceeding ‘git’If the input is ‘clone’, then it will run the command, print to the console which directory you are going to ‘cd’ into and then ‘cd’ into the cloned repositoryIf the input is not ‘clone’, it will execute the command accordinglyWrapping Things UpWhile we didn’t take a deep dive into BASH profiles, I hope this article gives you a basic understanding of what they are and how they can help.

Because shell scripts are written in a different language, the syntax and built-in commands might feel foreign.

I implore that if you’re interested, to do some research of your own to write custom scripts.

Below are a few resources that might give you some more insight.

Happy coding!An Introduction to Useful Bash Aliases and Functions | DigitalOceanThe more time you spend on the Linux command line, the more you will begin to realize that you tend to use the same…www.


comGit Command-Line ShortcutsA lot of my time is spent in Terminal and a majority of it is spent typing Git commands.

I created a set of keyboard…jonsuh.

com30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X – nixCraftAn bash alias is nothing but the shortcut to commands.

The alias command allows the user to launch any command or group…www.



. More details

Leave a Reply