Shell Tutorials
Shell is a C language program, he is a user using Linux bridge, Shell is both a command language, but also a programming language.
The Shell refers to an application that provides an interface through which users access the operating system kernel.
Ken Thompson's SH is the first Unix shell Windows Explorer to be a typical graphical interface shell.
Shell Script
Shell programming is like Java PHP programming, as long as there is a text editor that can write code and a script interpreter that can explain execution.
There are many types of shell in Linux, 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 focuses on bash, the Bourne Again Shell, which is widely used in daily work due to its ease of use and free, while bash is the default shell for most Linux systems.
In general, people do not differentiate between the Bourne shell and the Bourne Again shell, so, like #!/bin/sh, it can also be changed to #!/bin/bash.
#! Tells the system that the program specified after the path is the shell that interprets this script file.
First shell script
Open a text editor (you can use the Vi/vim command to create a file), a new file test.sh, the extension sh (sh for Shell), the extension does not affect the script execution, see knowingly
Well, if you write a shell script in PHP, the extension is good for PHP.
Enter some code, the first line is usually this:
Instance
#!/bin/bash
echo "Hello world!"
#! is a contract tag that tells the system what interpreter the script needs to execute, even if it uses a shell
The echo command is used to output text to a window.
There are two ways to run a Shell script:
1. As an executable program
Save the above code as test.sh and CD to the appropriate directory
chmod +x./test.sh #使脚本具有执行权限
./test.sh #执行脚本
Note that it must be written./test.sh instead of test.sh run other binary programs as well, write directly test.sh Linux system will go to PATH where there is no test.sh
2. As an interpreter parameter
This works by running the interpreter directly, whose parameters are the file names of the shell scripts, such as:
/bin/sh test.sh
/bin/php test.sh
Scripts that run this way do not need to specify the interpreter information on the first line
Linux Shell Tutorials