Shell is a program that takes commands from the keyboard and give that command to operating system to execute.
Simply put it is an interface that gives human users or programs all of the operating system services.
operating system shells use either a command-line interface (CLI)(terminals) or graphical user interface (GUI).
#Shell Types
So am going to be focusing more on the Linux development environment as it is the best Os(operating system) to learn about shell, In Linux there are two major types of Shells:-
Bourne shell:- use the $ character is the default prompt.
C shell:- use the % character is the default prompt.
#Terminal
Terminal(terminal emulator) is a program that lets you interact with the shell, simply is the place that you type your commands on to interact with the shell to reach the operating system.
#Shell Scripts
Shell scripts is a file that consists of a list of command that are executed in order.
Good Practice:- always put a comment explaining the step using the command #.
Shell scripts and functions are both interpreted. This means they are not compiled.
All the scripts would have the .sh extension. Before you add anything else to your script, you need to alert the system that a shell script is being started. This is done using the shebang construct.
#!/bin/sh
#Create and execute a Shell Script
To create a shell script we first create a file with or without .sh extension.
Now that we create the file we need to make sure the operating system knows that this is a shell script file, we do that by always adding a shebang command at the start of the line.
#! *this is a shebang
#!/bin/sh
β Execute the file using the Bourne shell, or a compatible shell, assumed to be in the /bin directory
#!/bin/bash
β Execute the file using the Bash shell
#!/usr/bin/pwsh
β Execute the file using PowerShell
#!/usr/bin/env python3
β Execute with a Python interpreter, using the env program search path to find it
Now that we have created the shell script in Linux, we need to give it the permission to execute, Don't worry if you don't know about shell permission am going to post a hole blog on the topic.
We do that by using the command:
chmod +x
To execute any shell file we use the command.
./<SCRIPT_NAME>
Now the script we created prints the current directory.
READ: to read more on shebang
Top comments (0)