The shell is the interface that communicates the user commands to the kernel by converting the commands into the machine language which is understandable by the machines. There are different types of shells like the Bourne Again Shell known as bash, the Bourne Shell (sh), and the Z-shell (zsh).
The Raspberry Pi comes with the bash shell by default so, in this write-up, we will explore the usage of the bash shell in the Raspberry Pi.
What is a bash shell
A bash shell is the short form of the Bourne Again Shell that is the advanced form of the Bourne shell and is used in the UNIX operating systems including the distributions of the Linux. A bash shell was used as a default shell in the macOS till 2019 then zsh replaced it, moreover, the bash shell opens just like a DOS window with a black background and allows the users to type different commands for performing some specific tasks on the machine. We can also type the different commands in the text file to run some particular tasks and then name the file with the extension of the “sh”. This file will be executable and is known as the shell script.
What are some common commands of the bash
There are different commands that can be used in the bash shell for different purposes, if you want to list down the contents of the directory, you can use the command:
Similarly to navigate some directory we use the “cd” command, for example, we will navigate to the “Downloads” directory in the bash:
To make a directory in the Downloads directory, we can use the “mkdir” command:
List down the contents to confirm the creation of the “LinuxHint” directory in the bash:
To remove the directory in the bash, we will use the rmdir command:
To update the packages of the operating system in the bash, run the command:
To extract the information of the CPU in the bash, we will execute the command:
These are some of the basic commands of the bash that are used while using the Raspberry Pi operating system using the bash.
What is the bash scripting
The bash script is the executable file containing the series of the commands of the bash, and we can run the multiple bash commands of the terminal by running a simple file. To understand this, we will open a text file with the help of the nano editor using the “sh” extension with the name of the file:
In the newly open file, we will first type the “#!/bin/sh” which tells the computer the pattern of the execution of the command, and this particular line is known as the shebang. We will create a script, make the directory with the name “MyDirectory”, and then create a file ”MyFile”:
mkdir MyDirectory
cd MyDirectory
touch MyFile
Exit the nano editor by saving the file and then run the command to execute the code of the file:
To confirm the creation of the directory and the file, we will display the contents of the directory “MyDirectory” using the command:
The directory and file has been successfully created with the execution of the myFirstBashScript file.
Conclusion
Bash is a widely used shell and comes with many advantages. It is a user-friendly shell as it contains the manual of almost all the commands which helps us to get the information on the usage of the commands. In this write-up, we have explored the bash, some of its basic commands, and finally, bash scripting.