Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commonly used shell variables

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what the commonly used shell variables are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Some commonly used shell variables

$# number of parameters passed to the script

$* display all parameters passed to the script in a single string (can be greater than 9)

The ID number of the current process in which the $script is running

$! The ID number of the last process running in the background

$@ is the same as $#, but use it in quotes and return each parameter in quotation marks

$- displays the current options used by shell

$? Displays the exit status of the last command, with 0 indicating no error (this variable is also often used to print output to mark whether a shell command or function is executed correctly when a script is debugged, but note that $? It records the exit status of the most recent function or command, so you should print immediately to get the correct information)

Use of $0

In the variable, there is a location variable $n, which is used to store the parameters passed in during the function call or script execution, where $0 represents the function name or script name. it is important to note that the script name passes the script name that contains the full path. The first through ninth parameters are passed from $1 to 9. Such parameters cannot be more than nine. If more than nine, you can use the shift instruction that will be mentioned below to read them.

Because $0 holds the function name or script name, we can output the call information through echo $0, but since we are storing the full path name, we can use a shell command to get the script name, basename $0 will get the part of the name of $0, and dirname $0 will get the part of the path of $0.

The above is all the contents of the article "what are the commonly used shell variables?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report