A shell script, what is its command parameter?
First, shell scripting and scripting like Python can use parameters as well;
Secondly, the shell parameters are divided into positional parameters and internal parameters;
Where, positional parameter: is the parameter provided by the system, is that we generally say that an array of the first 1,2,3 ... element; you can get a parameter in the form of a $i, which is obviously $ is the program itself, and it's just the number one argument. Here's the thing to note, even if you execute the script with SH xxx.sh, $ 0 is still xxx.sh, not sh! This is consistent with our Perl python.
Internal parameters:
Copy Code code as follows:
$-----The name of the current program is actually an internal parameter, different from $1,$2 ... because it has to be!
$#----The total number of arguments passed to the program, which is the legendary array size
$? ----the previous code or shell program to exit in the shell, if the normal exit is returned 0, otherwise not 0 value.
$*----A string of all the parameters passed to the program.
$@----with "parameter 1" "Parameter 2" ... Save all parameters in the form
$$----This program's (process ID number) PID
$! ----The PID of the previous command
In this way, even with a shell, you can write powerful, interactive, and user-friendly scripting programs.
Finally, note that Python performs system commands in two different ways:
Os.system (CMD): direct one or a group of system commands cmd; do not return execution output that is the result; if executed under the Python command line, the output is output directly.
For example: Os.system (' ls-l ')
Os.open (cmd[, mode= ' R ' [, BufSize]]): The document's comment is to open a pipe from cmd, or open a pipe to CMD, and return the output as a file Object!
For example: t = os.popen (' ls *.gff '). ReadLines (); Print T
Summary, combined with the above two parts, you can flexibly handle the Python script and shell interaction.