In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the "shell command line parameter usage tutorial" related knowledge, in the actual case operation process, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
What are the command parameters of a shell script?
First of all, shell scripting can use parameters as well as scripting like python
Secondly, shell parameters are divided into position parameters and internal parameters.
Among them, the position parameter: it is the parameter provided by the system, which is what we generally call the first, second and third of an array. Element; you can get a parameter in the form of $I, obviously $0 is the program itself, and $1 is the first parameter; note here that even if you execute the script as sh xxx.sh, $0 is still xxx.sh, not sh! This is consistent with our perl python.
Internal parameters:
The code is as follows:
$0-the name of the current program, which is actually an internal parameter, is different from $1. Because it must have!
$#-the total number of parameters passed to the program, that is, the size of the legendary array
$? when the last code or shell program exits in shell, it returns 0 if it exits normally, and vice versa.
$*-the string of all parameters passed to the program.
$@-with "Parameter 1" and "Parameter 2". Save all parameters in form
$$- (process id number) pid of this program
$!-pid of the previous command
In this way, even with shell, you can write powerful and interactive scripts.
Finally, note two different ways in which python executes system commands:
Os.system (cmd): a direct one or a set of system commands cmd; does not return the execution output as a result; if it is executed under the command line of python, the output is output directly.
For example: os.system ('ls-l')
Os.open (cmd [, mode='r' [, bufsize]]): the comment of the document is to open a pipe from cmd, or to 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 deal with the interaction between python scripts and shell.
This is the end of the "shell command line parameter usage tutorial". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.