Linux Series Tutorials (20) shell overview of--linux and how to execute scripts

Source: Internet
Author: User

Starting with this blog, we'll go into the Linux shell Script learning, which is particularly important for Linux learning enthusiasts and a particularly interesting section, as well as the shell script, like the java,php-like programming language we know, through shell scripting, We can do a lot of interesting apps. It is also the most important to find pleasure in learning.

In this blog we will first introduce you to what is the shell, and the basic functions of bash.

1. What is the Shell?

And what you usually say is that the shell is a programming language is actually not exactly right.

①, Shell is a command-line interpreter that provides users with an interface system-level program that sends requests to the Linux kernel to run programs, allowing users to start, suspend, stop, or even write programs with the shell.

For example, the interface we operate now is the shell, and we enter some commands to translate the machine language through the shell, and then the hardware to execute the commands.

②, Shell is a very powerful programming language, it is easy to write, easy to debug, but also strong flexibility. The shell is the scripting language that interprets execution, and the Linux system commands can be invoked directly in the shell.

  

In fact, Windows is similar to the shell is its graphical interface, we open the file in the Windows system, delete files and so on, is to send commands to the Windows system.

2. Shell classification

  

  

  

3. View Shell:/etc/shells supported by Linux system

  

We can switch directly to the shell name in the shell interpreter.

  

4. Echo Output command

This command if you have learned Java similar to SYSTEM.OUT.PRINTLN (), if you have learned the C language similar to printf (), the syntax in the shell is as follows:

echo "Options" "Output content"

-E represents a character conversion that supports backslash control, which is the escape character.

  

Example:

  

5. How to execute the script

First we write a shell script. With VI hello.sh, open the hello.sh file and add the following to the file:

  

①, we say that the Linux system is not differentiated file suffix name, here we learn bash, so create file hello.sh, suffix name preferably plus. SH (although no problem), it is easy for us to identify.

②, the first line of the script #!, this is a convention tag that tells the system what interpreter the script needs to execute, even if it uses a shell, so learning bash, the first line is fixed #!/bin/bash. This is not to be omitted.

Once created, the script is then executed in the following two ways:

①, as an executable program
Cd/tmp                     #进入到脚本所在的目录chmod +x./hello.sh   #使得脚本具有可执行权限./hello.sh                  #执行脚本

Note, be sure to write./hello.sh, not hello.sh, run other binary programs as well, direct write Hello.sh,linux system will go to the PATH to find there is no call hello.sh (this is the configuration of the environment variable later), and only/bin ,/sbin,/usr/bin,/usr/sbin, etc. in path, your current directory is usually not in path, so write hello.sh will not find the command, to use./hello.sh tells the system that it is looking in the current directory.

  

②, as an interpreter parameter

That is to run the interpreter directly, whose parameters are the file name of the shell script, as follows:

/bin/sh hello.sh or Bash hello.sh

Note: This way of executing the script does not require the first line to be written on #!/bin/bash.

Linux Series Tutorials (20) shell overview of--linux and how to execute scripts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.