Shell Script Start Tutorial

And the difference between Shell

Shell is a program written in C, it is the user to use Linux bridge.

Shell That is a command language, but also a programming language.

Shell refers to an application, the application provides a number of commands, users can go to access the operating system kernel services via these commands.

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

Shell online tools

Shell script, the script is a program written to Shell, Windows-like bat script, except that the bat is for the Windows operating system, while Shell script for Linux operating systems.

Script programming environment

  • text editor
  • Explain the script interpreter to execute the
    common explanation has:
    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)
    ......

General use Bash, is the Bourne Again Shell, Bash is the default most Linux systems Shell.

Shell Script leading #! Tells the system to explain the path of this program Shell script file, for example, the following Shell Scirpt execution path to / bin / bash

#!/bin/bash

The first Shell Script

Open a text editor (you can use vi / vim vs code or written), create a new file test.sh, extension sh (sh behalf shell), the extension does not affect the execution of the script.

#!/bin/bash
echo "Hello World !"

#! Convention is a tag that tells the system what the script requires an interpreter to perform that which Shell use.
echo command for outputting the text window.

Run Shell Script There are two ways:

1. as an executable program

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

chmod +x ./test.sh
./test.sh

Attention must be written ./test.sh, rather than test.sh, run the other binary programs, too, write directly test.sh, linux PATH system will go in search of anyone named test.sh, and only / bin , / sbin, / usr / bin, / usr / sbin and so on in the PATH, your current directory is usually not in the PATH, so test.sh will not find written order, tells the system to use ./test.sh say , to find in the current directory.

2. As explained parameters

/bin/sh test.sh

This script is run, it is unnecessary to specify the first line of the script interpreter information

FIG operating results as follows:

 
 

Guess you like

Origin www.cnblogs.com/ryanzheng/p/11563100.html