Table of Contents
bash
sh
ash
csh
ksh
Compiled Language
Interpreted Language
To use Shell scripts is based on:
Home Java javaTutorial A brief introduction to shell programming

A brief introduction to shell programming

Jun 26, 2017 am 11:20 AM
shell Introduction programming

Shell itself is a program written in C language. It is a bridge for users to use Unix/Linux. Most of the user's work is completed through Shell. Shell is both a command language and a programming language. As a command language, it interactively interprets and executes commands entered by the user; as a programming language, it defines various variables and parameters, and provides many control structures found only in high-level languages, including loops and branches.

Although it is not part of the Unix/Linux system kernel, it calls most of the functions of the system core to execute programs, create files, and coordinate the running of various programs in a parallel manner. Therefore, for users, the shell is the most important utility program. In-depth understanding and proficiency in the characteristics and usage of the shell are the keys to making good use of the Unix/Linux system.

It can be said that the proficiency of using shell reflects the user's proficiency in using Unix/Linux.

Shell has two ways to execute commands:

  • Interactive (Interactive): interprets and executes the user's command, the user enters a command, Shell will interpret and execute one.

  • Batch processing (Batch): The user writes a Shell script (Script) in advance, which contains many commands, so that the Shell can execute these commands at once without having to type the commands one by one. .


Shell scripts are very similar to programming languages. They also have variables and flow control statements, but Shell scripts are interpreted and executed and do not need to be compiled. The Shell program reads line by line from the script. Fetching and executing these commands is equivalent to a user typing the commands in the script line by line into the Shell prompt for execution.

Shell beginners please note that in daily applications, it is recommended not to use the root account to run Shell. As an ordinary user, you cannot damage the system whether intentionally or unintentionally; but if you are root, it is different. Just typing a few letters may lead to catastrophic consequences.

Common shell script interpreters on Unix/Linux include bash, sh, csh, ksh, etc. It is customary to call them a kind of Shell. We often talk about how many kinds of Shell there are, but what we are actually talking about is the Shell script interpreter.

bash

Bash is the standard default shell of Linux. This tutorial is also based on bash. bash was jointly completed by Brian Fox and Chet Ramey. It is the abbreviation of BourneAgain Shell and has a total of 40 internal commands.

Linux uses it as the default shell because it has the following features:

  • You can use functions similar to doskey under DOS, use the arrow keys to browse and quickly Enter and modify commands.

  • Automatically give commands starting with a certain string by searching for matches.

  • contains its own help function. You only need to type help at the prompt to get relevant help.

sh

sh Developed by Steve Bourne, it is the abbreviation of Bourne Shell. sh is the standard default shell of Unix.

ash

ash shell was written by Kenneth Almquist. It is a small shell that takes up the least system resources in Linux. It only contains 24 internal commands, so it is very inconvenient to use.

csh

csh is a relatively large kernel of Linux. It is compiled by a total of 47 authors represented by William Joy and has a total of 52 internal commands. This shell actually points to a shell such as /bin/tcsh. In other words, csh is actually tcsh.

ksh

ksh is the abbreviation of Korn shell, written by Eric Gisin, with a total of 42 internal commands. The biggest advantage of this shell is that it is almost completely compatible with the commercial version of ksh, so you can try the performance of the commercial version without spending money to buy the commercial version.

Note: bash is the abbreviation of Bourne Again Shell, which is the standard default shell of Linux. It is based on Bourne shell and absorbs some features of C shell and Korn shell. bash is fully compatible with sh, that is to say, scripts written in sh can be executed in bash without modification.

Compiled Language

Many traditional programming languages, such as Fortran, Ada, Pascal, C, C++ and Java, are compiled languages. This type of language needs to convert the source code we wrote into object code (object code) in advance. This process is called "compilation".

When running the program, read the object code directly. Since the compiled object code is very close to the bottom layer of the computer, the execution efficiency is very high, which is the advantage of compiled languages.

However, since most compiled languages ​​operate at the bottom level and deal with bytes, integers, floating point numbers or other machine-level objects, implementing a simple function often requires a large amount of complex code. For example, in C++, it is difficult to perform simple operations such as "copy all files in one directory to another directory".

Interpreted Language

Interpreted language is also called "scripting language". When executing this type of program, the interpreter needs to read the source code we wrote and convert it into object code, which is then run by the computer. Because each time the program is executed, there is an extra compilation process, so the efficiency is reduced.

The advantage of using scripting programming languages ​​is that they mostly run at a higher level than compiled languages ​​and can easily handle objects such as files and directories; the disadvantage is that they are usually not as efficient as compiled languages. However, the trade-off is that it is usually worthwhile to use script programming: a simple script that takes an hour to write may take two days to implement the same function in C or C++, and generally speaking, the script execution speed is fast enough. , fast enough for people to ignore its performance problems. Examples of scripting programming languages ​​include awk, Perl, Python, Ruby, and Shell.

To use Shell scripts is based on:

  • Simplicity: Shell is a high-level language; through it, you can express complex operations concisely.

  • Portability: Using the functions defined by POSIX, the script can be executed on different systems without modification.

  • Easy to develop: a powerful and useful script can be completed in a short time.

The above is the detailed content of A brief introduction to shell programming. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Remove duplicate values ​​from PHP array using regular expressions Remove duplicate values ​​from PHP array using regular expressions Apr 26, 2024 pm 04:33 PM

How to remove duplicate values ​​from PHP array using regular expressions: Use regular expression /(.*)(.+)/i to match and replace duplicates. Iterate through the array elements and check for matches using preg_match. If it matches, skip the value; otherwise, add it to a new array with no duplicate values.

The difference between PHP functions and Shell functions The difference between PHP functions and Shell functions Apr 24, 2024 pm 06:39 PM

The main differences between PHP functions and Shell functions are security (PHP functions are more secure), reliability (Shell functions vary by operating system), functionality (Shell functions are more powerful but limited by the shell), and performance (PHP functions are usually faster) and complexity (Shell functions are more complex). They are both used for file system, process and command operations, but PHP functions are built-in, while Shell functions are called through an external shell. Therefore, in server file download scenarios, the file_put_contents() function is safer, while the wget command is more flexible.

What is programming for and what is the use of learning it? What is programming for and what is the use of learning it? Apr 28, 2024 pm 01:34 PM

1. Programming can be used to develop various software and applications, including websites, mobile applications, games, and data analysis tools. Its application fields are very wide, covering almost all industries, including scientific research, health care, finance, education, entertainment, etc. 2. Learning programming can help us improve our problem-solving skills and logical thinking skills. During programming, we need to analyze and understand problems, find solutions, and translate them into code. This way of thinking can cultivate our analytical and abstract abilities and improve our ability to solve practical problems.

Collection of C++ programming puzzles: stimulate thinking and improve programming skills Collection of C++ programming puzzles: stimulate thinking and improve programming skills Jun 01, 2024 pm 10:26 PM

C++ programming puzzles cover algorithm and data structure concepts such as Fibonacci sequence, factorial, Hamming distance, maximum and minimum values ​​of arrays, etc. By solving these puzzles, you can consolidate C++ knowledge and improve algorithm understanding and programming skills.

Build browser-based applications with Golang Build browser-based applications with Golang Apr 08, 2024 am 09:24 AM

Build browser-based applications with Golang Golang combines with JavaScript to build dynamic front-end experiences. Install Golang: Visit https://golang.org/doc/install. Set up a Golang project: Create a file called main.go. Using GorillaWebToolkit: Add GorillaWebToolkit code to handle HTTP requests. Create HTML template: Create index.html in the templates subdirectory, which is the main template.

Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Oct 11, 2024 pm 08:58 PM

Pythonempowersbeginnersinproblem-solving.Itsuser-friendlysyntax,extensivelibrary,andfeaturessuchasvariables,conditionalstatements,andloopsenableefficientcodedevelopment.Frommanagingdatatocontrollingprogramflowandperformingrepetitivetasks,Pythonprovid

The Key to Coding: Unlocking the Power of Python for Beginners The Key to Coding: Unlocking the Power of Python for Beginners Oct 11, 2024 pm 12:17 PM

Python is an ideal programming introduction language for beginners through its ease of learning and powerful features. Its basics include: Variables: used to store data (numbers, strings, lists, etc.). Data type: Defines the type of data in the variable (integer, floating point, etc.). Operators: used for mathematical operations and comparisons. Control flow: Control the flow of code execution (conditional statements, loops).

Use golang's error wrapping and unwinding mechanism for error handling Use golang's error wrapping and unwinding mechanism for error handling Apr 25, 2024 am 08:15 AM

Error handling in Go includes wrapping errors and unwrapping errors. Wrapping errors allows one error type to be wrapped with another, providing a richer context for the error. Expand errors and traverse the nested error chain to find the lowest-level error for easy debugging. By combining these two technologies, error conditions can be effectively handled, providing richer error context and better debugging capabilities.

See all articles