List of special variables |
Variable |
Meaning |
$ |
File name of the current script |
$n |
Arguments passed to the script or function. N is a number that represents the first few parameters. For example, the first parameter is $ $, and the second argument is $ A. |
$# |
The number of arguments passed to the script or function. |
$* |
All parameters passed to the script or function. |
[Email protected] |
All parameters passed to the script or function. When enclosed by double quotation marks (""), it is slightly different from $*, as will be mentioned below. |
$? |
The exit state of the last command, or the return value of the function. |
$$ |
The current shell process ID. For Shell scripts, this is the process ID where the scripts are located. |
List of string operators |
Operator |
Description |
Example |
= |
Detects whether two strings are equal and returns true for equality. |
[$a = $b] returns FALSE. |
!= |
Detects whether two strings are equal and returns true if they are not equal. |
[$a! = $b] Returns TRUE. |
-Z |
Detects whether the string length is 0 and returns true for 0. |
[-Z $a] returns false. |
-N |
Detects whether the string length is 0 and does not return true for 0. |
[-Z $a] returns true. |
Str |
Detects whether the string is empty and does not return true for null. |
[$a] returns TRUE. |
The Shell contains scripts that can be used:
. FileName
Or
SOURCE filename
The effect of the two methods is the same, for simplicity, the dot (.) is generally used, but note the dot (.) There is a space in the middle of the file
List of file test operators |
Operator |
Description |
Example |
-B File |
Detects if the file is a block device file, and returns True if it is. |
[-B $file] returns FALSE. |
-C file |
Detects if the file is a character device file, and returns True if it is. |
[-B $file] returns FALSE. |
-D File |
Detects if the file is a directory, and returns True if it is. |
[-D $file] returns false. |
-F File |
Detects if the file is a normal file (neither a directory nor a device file), and returns True if it is. |
[-F $file] returns TRUE. |
-G file |
Detects if the file has a SGID bit set, and returns True if it is. |
[-G $file] returns false. |
-K File |
Detects if the file has a sticky bit set (Sticky bit), and returns True if it is. |
[-K $file] returns false. |
-P File |
Detects if the file is a named pipe, and returns True if it is. |
[-P $file] returns false. |
-U file |
Detects if the file has a SUID bit set, and returns True if it is. |
[-U $file] returns false. |
-R File |
Detects if the file is readable and returns true if it is. |
[-R $file] returns TRUE. |
-W File |
Detects if the file is writable and returns true if it is. |
[-W $file] returns TRUE. |
-X File |
Detects if the file can be executed and, if so, returns True. |
[-X $file] returns TRUE. |
-S file |
Detects whether the file is empty (the file size is greater than 0) and does not return true for null. |
[-S $file] returns TRUE. |
-E File |
Detects whether the file (including the directory) exists and, if so, returns True. |
[-e $file] returns TRUE. |
Shell Code Common table