In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to understand the location variable parameters in the Shell script". In the daily operation, I believe that many people have doubts about how to understand the location variable parameters in the Shell script. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "how to understand the location variable parameters in the Shell script". Next, please follow the editor to study!
$#: number of parameters passed to the script
$*: displays all parameters passed to the script as a single string. Unlike location variables, this option can have more than 9 parameters
$: ID number of the current process in which the script is running
$!: the process ID number of the last process running in the background
$@: same as $#, but use it in quotation marks and return each parameter in quotation marks
$-: displays the current options used by shell, with the same function as the set command
$?: displays the exit status of the last command. 0 indicates that there is no error, and any other value indicates an error.
The code is as follows:
#! / bin/sh
# param.sh
# $0: full pathname of the file
Echo "path of script: $0"
# obtain the file name using the basename command file path
Echo "name of script: $(basename $0)"
# $1: parameter 1
Echo "parameter 1: $1"
# $2: parameter 2
Echo "parameter 2: $2"
# $3: parameter 3
Echo "parameter 3: $3"
# $4: parameter 4
Echo "parameter 4: $4"
# $5: parameter 5
Echo "parameter 5: $5"
# $#: the number of parameters passed to the script
Echo "The number of arguments passed: $#"
# $*: display the contents of all parameters I
Echo "Show all arguments: $*"
# $: the ID number under which the script is currently running
Echo "Process ID: $"
# $?: return code
Echo "errors: $?"
Enter. / param.sh hello world
The code is as follows:
[firefox@fire Shell] $. / param.sh hello world
Path of script:. / param.sh
Name of script: param.sh
Parameter 1: hello
Parameter 2: world
Parameter 3:
Parameter 4:
Parameter 5:
The number of arguments passed: 2
Show all arguments: hello world
Process ID: 5181
Errors: 0
At this point, the study on "how to understand the location variable parameters in the Shell script" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.