What is Bash and What Does it Do?
Bash is a command line tool. Every terminal has a command line that you use to communicate with your computer’s OS (Operating System).
Whenever you open your computer’s Terminal, you open a shell. Bash is a type of shell or a command line shell.
Bash is just one of many command line shells (tools), including Zsh, and Fish.
Bash, Zsh, and Fish are just different shell flavors that by and large serve the same purpose, they provide a command line that you use to write instructions to your computer. Each has individual features that make some choose one over the other — but that’s for a different article.
Many are using a specific shell without even realizing it (you could have installed it as part of following a tutorial). If you want to check which shell you’re using, open your terminal and type:
echo $0
If you’re using bash, your output will be:
-bash
You can also use:
echo $SHELL
The difference is that echo $0 gives you the current shell you’re working inside, while echo $SHELL gives you your terminal default shell. So if you close your terminal and open it again, the output you get from running echo $SHELL is your default shell.
This is good to know because sometimes you will be running multiple brands of shells inside your terminal, which can get confusing, but that’s where the echo $0 command is handy.
🎯 Note: if you’re running the Ubuntu OS on your computer, your default shell is Bash.
Now Learn What is Bashr
Learn how to create a .bashrc shell script file via the macOS Terminal and how to open it with the nano editor.
.bashrc is a bash shell script (configuration) file used for initializing an interactive shell session. It’s specifically used for interactive non-login shells.
Now let’s learn how to create a .bashrc file and how to open and modify it via the nano editor that comes built-in with macOS.
Create a .bashrc file
To create a .bashrc file, open your Mac Terminal and run this command:
touch ~/.bashrc
When you create bash files they will typically be located in the root directory of your Mac user account:
/users/your-account
Since bash files are hidden files by default, you can use this list command to show them inside your Terminal:
ls -lha
Open .bashrc via the nano editor
To open your new .bashrc file, you can use the built-in GNU nano editor (mostly referred to as “nano”).
Run this command inside your terminal to open your.bashrc file via nano:
nano ~/.bashrc
After opening the file inside nano, you can edit it.
Error: ⚠️ Warning: be careful when making changes to any bash script file, or any hidden file in general. If you follow a tutorial that requires modifying bash files, make sure you pay attention to the instructions you get, so you don’t screw anything up. If you’re in doubt, EXIT without saving your changes.
Save and quit Nano
If you have added anything to your bash files via nano, you can save and quit your data like this:
- First hit ctrl + x
- Then hit y (yes) to confirm you want to save the changes.
- Then hit enter to exit the nano editor.
Quit nano without saving:
- First hit ctrl + x
- Then hit n (no) to confirm that you want to quit without saving changes.
Info: 📚 Read more about Bash Shell Command Line
🎯 Learn how to become a full-stack software developer with essential skills, technologies, and portfolio projects. Find out the roadmap…
I have been struggling with this error for about one week and in dev mode everything is working perfectly but…
Great Blog so far, I was facing issues with understanding bash and what it actually does. Thanks so much
I am happy you did find this resource helpful😊