shell command

#!/bin/sh means that this script uses /bin/sh to interpret and execute: #! is a special symbol, and the root behind it is the path of the shell that interprets this script.
$bash $ indicates the system prompt, $ indicates that the user is a normal user, and the prompt of the super user is #.
Bash is a kind of shell, which is the most commonly used shell under linux.
$bash means to execute a subshell, this subshell is bash.
Note that "#!" is used at the beginning of each script, which means to tell your system that the execution of this file needs to specify an interpreter. After the #! is followed by a pathname. This pathname specifies an interpreter The program of the command in the script. This program can be a shell, a programming language or any general program. The specified program interprets and executes the command in the script from the beginning (starting from the line below the #! line),
note: #! The pathname given must be correct, otherwise an error message will appear, usually "Command not found", which will be the only result you will get when you run the script.
If there is a #! line, then bash will treat it as a normal comment line.

$# is the number of arguments passed to the script
$0 is the name of the script itself
$1 is the first argument
passed to the shell script $2 is the number of arguments passed to the shell script The second parameter
$@ is a list of all parameters passed to the script
$* is a single string showing all parameters passed to the script, unlike positional variables, the parameters can be more than 9
$$ is the current process in which the script is running The ID number
$? is to display the exit status of the last command, 0 means no error, other means there is an error


file expression

integer variable expression
if [ -f file ] if file exists

if [ -d ... ] if the directory exists

if [ -s file ] if file exists and is not empty

if [ -r file ] if the file exists and is readable

if [ -w file ] if the file exists and is writable

if [ -x file ] if the file exists and is executable  


String variable expression
If [ $a = $b ] If string1 is equal to string2 Strings allow the use of an assignment sign as an equal sign

if [ $string1 != $string2 ] if string1 is not equal to string2      

if [ -n $string ] If string is not empty (not 0), return 0 (true) 

if [ -z $string ] if string is empty

if [ $sting ] If string is not empty, return 0 (similar to -n)       

Conditional expressions refer to variables with $ -eq -ne -lt -nt only for integers, not for strings, strings are equal to the assignment number =  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326314627&siteId=291194637