Latest web development tutorials

Shell Tutorials

Shell Tutorials

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

Shell refers to an application, the application provides an interface through which the user interface to access the operating system kernel services.

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

Shell online tools


Shell Scripting

Shell scripts (shell script), is a kind of shell scripts written.

Said shell industry usually refers to the shell script, but readers should know, shell and shell script are two different concepts.

Due habits of brevity, "shell programming" appearing herein refer to shell scripting, does not refer to the development of the shell itself.


Shell Environment

Shell programming with java, php programming, as long as one can write code in a text editor and a script interpreter to explain the implementation of it.

Linux's Shell many species are common:

  • 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 is concerned Bash, is the Bourne Again Shell, due to the ease of use and free, Bash is widely used in daily work. Meanwhile, Bash is the default for most Linux systems Shell.

In general, people do not distinguish between Bourne Shell and Bourne Again Shell, so, like #! / Bin / sh, it also can be changed to #! / Bin / bash.

#! Then tell the system path specified by the program that is interpreted Shell This script file.


The first shell script

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

Enter some code, the first line is generally like this:

Examples

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

Running instance »

"#!" Is a convention tag that tells the system what the script interpreter to execute, that is, which one to use Shell.

echo command is used to output text to a window.

Run Shell Script in two ways:

1, as an executable program

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

chmod +x ./test.sh  #使脚本具有执行权限
./test.sh  #执行脚本

Attention must be written ./test.sh, instead test.sh, running other binary programs, too, write directly test.sh, linux system will go there in search of PATH called test.sh, and only / bin , / sbin, / usr / bin, / usr / sbin and so on in the PATH, your current directory is usually not on the PATH, it will not find written test.sh command tells the system to use ./test.sh say , to find in the current directory.

2, as the explanatory parameter

This operation mode is run directly interpreter, its file name parameter is the shell script, such as:

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

This script is run, the first line does not need to specify the interpreter information, write useless.