Hello everyone, I am Cola, a dedicated original, willing to share the program ape. This series of tutorials will continue to be updated, you can search “IT Cola” on wechat to read the first time. Ebooks has a huge selection of free books that I’ve selected for you

Starting from this blog, we will enter the study of Linux shell script, which is a particularly important section for Linux learning enthusiasts, but also a particularly interesting section. Shell script is just like Java and PHP programming languages we know, through shell script, We can do a lot of interesting applications. The most important thing is to find fun in learning.

In this blog we are going to introduce you to what the shell is and the basic functions of Bash.

What is a Shell?

The common claim that the shell is a programming language is not entirely true.

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

For example, the interface we operate on now is shell. We input some commands, which are translated into machine language by shell, and then executed by hardware.

Shell is a very powerful programming language, it is easy to write, easy to debug, and flexible. The shell is a scripting language that explains execution. Linux system commands can be directly invoked in the shell.In fact, Windows is similar to shell is its graphical interactive interface, we open files in the Windows system, delete files and other operations, is to send commands to the Windows system.

2. Classification of Shell

3. Check the shells supported by Linux: /etc/shells

We can switch by typing the shell name directly in the shell interpreter

4. Echo output command

Println (); printf(); system.out.println ();

Echo [option] [output]

-e indicates the character conversion that supports backslash control, that is, the escape character.Example:

5. Script execution

Let’s start by writing a shell script. Run the vi hello.sh command to open the hello.sh file and add the following content to the file:Sh file with a.sh suffix (although it’s ok not to add it).

The first line of the script #! This is a convention flag that tells the system what interpreter the script needs to be executed with, that is, which shell to use. So learning bash, the first line is always #! / bin/bash. This cannot be omitted.

Once created, execute the script in either of the following ways:

① as an executable program

CD/TMP # Go to the directory where the script resides chmod +x./hello.sh # Make the script executableCopy the code

Sh. If you run any binary program, just write hello. Sh. Linux will look for a PATH called Hello. /usr/bin /sbin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbin /bin /usr/sbinThe shell script name is the name of the shell script.

/bin/sh hello.sh
或者
bash hello.sh
Copy the code

Note: Executing the script this way does not require #! / bin/bash.

This series of tutorials will continue to be updated, you can search “IT Cola” on wechat to read the first time. Reply ebook has a selection of books that I have selected for you