The shell script, as its name implies, is a script written for the shell, as long as there is a text editor and an interpreter that can execute the script.
There are many types of Shell in Linux, we can open a text editor (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 execution of the script, the first line is generally the case:
#!/bin/bash
echo "Hello world!"
#! is a contract tag that tells the system what interpreter the script needs to execute, and which Shell to use.
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, be sure to write./test.sh, not test.sh, run other binary programs as well, direct write Test.sh,linux system will go to the PATH to find there is no test.sh, and only/bin,/sbin,/USR/BIN,/USR /sbin wait in path, your current directory is usually not in path, so write test.sh will not find the command, to use./test.sh tells the system that it is looking in the current directory.
2. Here's the Shell echo command
Execution commands can use Echo to achieve more complex output format control
1. Display Normal string:
For example: Echo "It is a test"
The double quotes here are completely omitted, and the following commands are identical to the previous instance:
Echo It is a test
2. Show escape characters
echo "\" It is a test\ ""
The result is:
"It is a test"
3. Output strings As-is, without escaping or taking variables (in single quotes)
echo ' $name \ '
The output is:
$name \ "
4. Show command Execution results
Echo ' Date '
Note that the inverse single quote is used instead of the single quotation mark.
The result will show the current date
Sat 14:38:26 CST 2017
Knowledge and usage of shell in Linux