Bash is the shell, or command language interpreter, for Linux operating system.
Shell - Provides an interface between the user and the kernel.
A shell is a command-line interpreter and typical operations performed by shell scripts includes file manipulation, program execution, and printing text.
To execute an user-defined commands we need to run a program known as shell scripts.
.sh is the extension of a shell program. And it should be an executable one(The program should have proper file permission).
The .sh file should have the following file permission -rwxr-xr-x. To know more about file permission click here.
All commands are not user defined. Some of the commands are builtin. There are two types of Shell commands.
Types of shell commands:
Internal commands
External commands
Internal commands:
They are known as builtin commands. It is a part of the shell itself, i.e. built into the shell. Example: cd, pwd, grep, etc..,.
External commands:
Separate binaries stored in /sbin, /usr/sbin, /usr/bin, /bin, or /usr/local/bin directories. These can be find after installing an application. They can be modified.
Example: /usr/bin/java, /usr/bin/httpd, etc..,.
All shell scripts has an Shebang #!/bin/bash
A shebang is the first line of the file. It tells which was the interpreter to be used for execution.
Let us see a simple shell script that will print some content.
Create a file with your text editor as myfile.sh
jhony@ljlinux:~$ vim myfile.sh
Paste the below code inside the file.
Code:
#!/bin/bash
echo We started to learn shell script!!!
Make the file an executable one:
Change the permission of the file.
jhony@ljlinux:~$ chmod +x myfile.sh
Execute the file:
Execute the file using ./ or calling the whole path of the file.
jhony@ljlinux:~$ ./myfile.sh
We started to learn shell script!!!
jhony@ljlinux:~$ sh myfile.sh
We started to learn shell script!!!
Since we are just starting Im not going to dig deep into shell scripting now. We will start with basic operators and then working with files and directories using shell scripts and followed by installing and performing operations on applications. These all will be covered in the upcoming articles.
Basic Operators in Shell Scripting:
There are 5 basic operators in bash/shell scripting,
Comments