What is a shell?
Shell is an environment in which we can run commands, programs and Shell scripts. There are different versions of Shell, which differ only from the version of the operating system. Each version of Shell has its own set of recognized commands and functions.
Shell provides you with an interface to Unix systems. It collects input from you and runs programs based on that input. When a program completes, it displays the output (output) of that program.
The command prompt line Shell in Unix / Linux
Command prompt, $, is notified by Shell. While the prompt is displayed, you can enter a command.
Shell reads the input you enter after you press Enter. It determines the command you want to run by looking at the first word in your input. A word is an unbroken set of characters. Spaces and tabs separate words.
Here is a simple example of the date command that displays the current date and time:
$ date Thu Jun 25 08 : 30 : 19 MST 2009
You can customize your command prompt using the PS1 environment variable explained in the Work environment chapter.
Shell types in Unix / Linux
There are two main types of Unix in Unix:
- Bourne Shell style. If you are using a Bourne Shell, the command line is the default $ character.
- Type C Shell. If you are using C Shell type, the default prompt line is% character.
In Bourne Shell, there are other subtypes as follows:
Bourne Shell (sh)
Korn Shell (ksh)
Bourne Again Shell (bash)
POSIX Shell (sh)
In type C Shell there are other subtypes:
C Shell (csh)
TENEX / TOPS C Shell (tcsh)
The first Unix Shells were recorded in the mid-1970s by Stephen R. Bourne while he was working at the AT&T Bell Labs in New Jersey.
Bourne Shell is the first Shell to appear on Unix systems, so it is referred to as "the Shell".
Bourne Shell is usually installed as / bin / sh on most Unix versions. For this reason, it is Shell selected to write scripts to use on different versions of Unix.
In this chapter, we refer to most of the Shell concepts based on Bourne Shell.
Shell Scripts in Unix / Linux
The basic concept of a Shell script is a list of commands, which are listed in order of execution. A good Shell script will have comments, preceded by the # sign, describing the steps.
There are conditional checks, such as value A greater than value B, loops that allow us to handle large amounts of data, files to read and store data and variables to read and store data, and the script may include functions.
Shell scripts and functions are interpreted. This means they are not compiled.
We are going to write many scripts in the next tutorial. It can be a simple text file in which we place all necessary commands and structures that tell the Shell environment what is done and when it is done.
Examples of scripts in Unix / Linux
Suppose we create a test.sh. Remember that all scripts should have an .sh extension. Before you add anything to your script, you need to tell the system that a prepared Shell script is started. This is done using the shebang structure. For example:
#! / bin / sh
This command tells the system that the following commands are run by Bourne Shell. It is called a shebang because the # symbol is called a hash and the symbol! called a state.
To create a script that contains these commands, first place the shebang line and then add the commands:
#! / bin / bash pwd ls
Comments Shell in Unix / Linux
You can put Shell Comments in the script as follows:
#! / bin / bash # Author: Zara Ali # Copyright (c) Tutorialspoint.com # Script follows here: pwd ls
Now save the above content and make this script run as follows:
$ chmod + x test . sh
Now you have your Shell script ready to run as follows:
$ ./ test . sh
This produces the following result:
/ home / amrood index . jsp unix - basic_utilities . jsp unix - directories . jsp test . sh unix - communication . jsp unix - environment . jsp
Note : To run any of your programs in the current directory, you should run using ./program_name
Shell script extension in Unix / Linux
Shell scripts have some required structures that tell the Shell environment what to do and when to do it. Of course, most scripts here are more complicated than the ones introduced above.
Shell is a real, complete program language with variables, control structures and . No matter how complicated it is, however, it is still a list of commands executed in a way continuity.
The following scripts use the read command which receives input from the keyboard and assigns it to the PERSON variable and finally prints it on the STDOUT variable.
#! / bin / sh # Author: Zara Ali # Copyright (c) Tutorialspoint.com # Script follows here: echo "What is your name?" read PERSON echo "Hello, $ PERSON"
Below is a sample run of the script above:
$ ./ test . sh What is your name ? Zara Ali Hello , Zara Ali $
According to Tutorialspoint
Previous article: Micro editor in Unix / Linux
Next lesson: Use variables in Shell
You should read it
May be interested
- Steps to fix 'Shell Infrastructure Host Has Stopped Working' error in Windowsis your windows device showing 'shell infrastructure host has stopped working' error? in most cases, this problem occurs when running the application on a windows guest account.
- Basic Shell commands in Linuxworking on the linux operating system you cannot not know the basic shell commands. for ease of operation on linux, tipsmake.com has compiled some basic linux shell commands, please consult.
- Code Python on the browser with these free online Python interpretersyou should use an interactive interactive shell. these are sites that allow you to write, execute python code and immediately see the results, without installing anything.
- What is 'Windows Shell Experience Host' and why run on the computer?have you ever seen a process called windows shell experience host in task manager window? if you have seen, do you know what this process is? and why does it sometimes 'eat' a lot of cpu and computer memory? this article will explain to you the windows shell experience host process on task manager.
- Basic Shell operatorsthere are many operators supported by each shell. our tutorial is based on the default shell (bourne) so we are discussing bourne shell operators in this chapter.
- Math functions are available in Shellmost parts of the tutorial are mostly built on bourne shell, but this page lists all the built math functions available in the korn shell.
- Suggested solution when the computer reports an EFI Shell version errorthe computer reports an efi shell version error and you don't know what to do in this case? tipsmake has some suggestions to help you fix it, find out right away!
- How to integrate Google account into GNOME Shelloverall, integrating your google account in gnome shell is very simple. in this article, we will learn how to integrate google account into gnome shell.
- How to use Open-Shell to create your own Start menu on Windows 10to address all of these existing problems, tipsmake found a free, open-source application that you can download today to create your own start menu - open-shell.
- How to open folders hidden on the system with the Shell command on Windows?on the operating system there are many hidden system folders that can be identified on the windows registry with the clsid key, the specific folder name and the folder location on your computer.