Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Sample Analysis of Shell tutorial

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you the "sample analysis of the Shell tutorial", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and study the "sample analysis of the Shell tutorial" this article.

Shell is a program written in C language, which is a bridge for users to use Linux. Shell is both a command language and a programming language.

Shell is an application that provides an interface through which users access the services of the operating system kernel.

Ken Thompson's sh is the first Unix Shell,Windows Explorer is a typical graphical interface Shell.

Shell script

Shell script (shell script) is a scripting program written for shell.

Shell in the industry usually refers to shell scripts, but readers should know that shell and shell script are two different concepts.

For habitual reasons, for the sake of brevity, the "shell programming" in this article refers to shell scripting, not to the development of shell itself.

Shell environment

Shell programming is the same as JavaScript and php programming, as long as there is a text editor that can write code and a script interpreter that can interpret and execute.

There are many kinds of Shell in Linux, and the common ones are:

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)

……

This tutorial focuses on Bash, or Bourne Again Shell, which is widely used in daily work because of its ease of use and free of charge. At the same time, Bash is the default Shell for most Linux systems.

In general, people don't distinguish between Bourne Shell and Bourne Again Shell, so, like #! / bin/sh, it can also be changed to #! / bin/bash.

#! Tell the system that the program specified in the subsequent path is the Shell program that interprets this script file.

The first shell script

Open a text editor (you can use the vi/vim command to create a file), create a new file test.sh, the extension is sh (sh on behalf of shell), the extension does not affect the execution of the script, see the meaning of the name is good, if you use php to write shell scripts, the extension is good with php.

Enter some code, and the first line usually looks like this:

Example #! / bin/bashecho "Hello World!" Run the instance »

#! Is a convention tag that tells the system what interpreter the script needs to execute, no matter which Shell is used.

The echo command is used to output text to the window.

There are two ways to run Shell scripts:

1. As an executable program

Save the above code as test.sh and cd to the appropriate directory:

Chmod + x. / test.sh # gives scripts the right to execute. / test.sh # execute scripts

Note, be sure to write as. / test.sh, not test.sh, and run other binary programs as well. Writing test.sh,linux directly will look for test.sh in PATH, but only / bin,/ sbin, / usr/bin,/usr/sbin, etc., are in PATH. Your current directory is usually not in PATH, so you can't find commands when written as test.sh. Use. / test.sh to tell the system Just look in the current directory.

2. As an interpreter parameter

This mode of operation is to run the interpreter directly, whose argument is the file name of the shell script, such as:

/ bin/sh test.sh/bin/php test.php

Scripts run in this way do not need to specify interpreter information on the first line, and it is useless to write them.

The above is all the content of the article "sample Analysis of the Shell tutorial". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report