playing Linux does not know the shell, that is, do not understand Linux. This statement is enough to witness the shell's position in Linux operations. Always want to write down the shell, but always do not know how to write, not because the shell is too difficult, but because she is too large, also may be because of their own shell capacity deficiencies, afraid can not be systematic to understand the shell, but to start eventually still want to start, Come on!
What is a shell?
The shell is the outermost layer of the operating system, and the shell can merge programming languages to control processes and files, as well as to start and control other programs. The shell manages the interaction between you and the operating system by prompting you to enter, explaining the input to the operating system, and then processing any result output from the operating system.
A shell is a command interpreter between a user and the operating system. The shell is a bridge between the user and the Linux operating system. The user can enter the command execution, and can use Shell script programming to run.
The shell itself is a program written in C, which is a bridge for users to use Unix/linux, and most of their work is done through the shell.
The shell is both a command language and a programming language. As a command language, it interprets and executes user-entered commands interactively, and as a programming language, it defines variables and parameters and provides many control structures in high-level languages, including loops and branches.
the difference between a shell and a compiled language
Compiled Languages
Many of the traditional programming languages, such as Fortran, Ada, Pascal, C, C + +, and Java, are compiled languages. These languages require that the source code that we have written be converted into a target tag (object codes), and this process is called "compiling". When you run the program, read the object code directly. Because the compiled object code is very close to the bottom of the computer, the execution is very efficient, which is the advantage of a compiled language. However, since most of the compiled languages work on the ground floor, dealing with bytes, integers, floating-point numbers, or other machine-level objects, it is often necessary to implement a simple function that requires a lot of complex code. For example, in C + +, it's hard to do simple things like "copy all files from one directory to another."
interpreted Language
interpreted language is also known as the "scripting language". When executing such a program, The interpreter (interpreter) needs to read the source code that we wrote and convert it to the target (object), which is then run by the computer. Because each execution of the program is more than the compilation process, so efficiency has decreased.
The benefits of scripting languages
The advantage of using scripting languages is that they are mostly run at a higher level than the compiled language and can easily handle objects such as files and directories, and the disadvantage is that they are often less efficient than compiled languages. However, the tradeoff is that scripting is usually worthwhile: a simple script that takes one hours to write, the same functionality written in C or C + +, can take up to two days, and, in general, the speed of the script execution is fast enough to let people ignore its performance problems. Examples of scripting languages are awk, Perl, Python, Ruby, and Shell.
the shell has two ways of executing commands:
Interactive (Interactive):explains the command that executes the user, the user enters a command, and the shell interprets the execution of a rule.
Batching (Batch):The user writes a shell script in advance, with a number of commands that allow the shell to execute the commands at once without having to hit the command one at a time.
Linux Shell types:
Common with:Bourne Shell (/usr/bin/sh or/bin/sh), Bourne Again Shell (/bin/bash), C Shell (/usr/bin/csh), K Shell (/usr/bin/ksh), Shell For Root (/sbin/sh) and so on. Different shell language syntax differs, so it cannot be exchanged for use.
The most commonly used shell is bash, the Bourne Again Shell, which is widely used in daily work due to its ease of use and free, and is the default shell for most Linux systems. Next, let's write a simple shell script. (The shell script general file name ends with. sh {not required, but necessary}, while the first line of the file defines the script as a shell script)
[[email protected] ~]# vim first.sh[[email protected] ~]# cat first.sh #!/bin/bash#date 2015.04.28#author jacken#use: This is my first shellecho "hello world!" [[email protected] ~]# bash first.sh hello world! [[Email protected] ~]# ./first.sh-bash: ./first.sh: permission denied[[email protected] ~]# chmod +x first.sh [[email protected] ~]# ./ first.shhello world! [[email protected] ~]#
Comments:
Think a lot of people learn the shell is from the "World, Hello!" "The beginning, Me too!
The shell is used for execution, so there is permission to execute (x), or Direct bash first.sh tells the system that this is a script (no need to execute permissions)
The first line of the #!/bin/bash is to specify the language of the script to explain, in addition to the first business "#" identifies which language, the remaining "#" after all is a comment, description.
A good shell will mark the date, the author, the version, the use, this is a good habit, otherwise when we write hundreds of lines of code, every other months or years, how to know what was written? 650) this.width=650; "src=" Http://img.baidu.com/hi/face/i_f32.gif "alt=" I_f32.gif "/>
This article is from the "Welcome to Linux World" blog, so be sure to keep this source http://linuxnote.blog.51cto.com/9876511/1639640
Linux Shell One shell introduction