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

How to analyze the meaning of shell variables $#, $@, $0 "1" 2 in linux

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article shows you how to analyze the meaning of shell variables $#, $@, $0 in linux. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

The meaning of the shell variables $#, $@, $0 in linux is explained as follows:

Variable description:

$

PID (ProcessID) of Shell itself

$!

The PID of the background Process that the Shell last ran

$?

The end code of the last run command (return value)

$-

Flag list set using the Set command

$*

List of all parameters. In the case of "$*" enclosed by "$", with "$1 $2". Outputs all parameters in the form of $n ".

$@

List of all parameters. In the case of "$@" surrounded by ", output all parameters in the form of" $1 "" $2 "…" $n ".

$#

Number of parameters added to Shell

, 0

The file name of the Shell itself

$1 million

The parameter values added to the Shell. $1 is the first parameter, $2 is the second parameter.

Example:

1 #! / bin/bash 2 # 3 printf "The complete list is% s\ n"$$" 4 printf "The complete list is% s\ n"$!" 5 printf "The complete list is% s\ n" $? "6 printf" The complete list is% s\ n "$*" 7 printf "The complete list is% s\ n" $@ "8 printf" The complete list is% s\ n "$#" 9 printf "The complete list is% s\ N "$0" 10 printf "The complete list is% s\ n"$1" 11 printf "The complete list is% s\ n" $2

Results:

[Aric@localhost] $bash params.sh 123456 QQThe complete list is 24249The complete list isThe complete list is 0The complete list is 123456 QQThe complete list is 123456The complete list is QQThe complete list is 2The complete list is params.shThe complete list is 123456The complete list is QQ the above is how to analyze the meaning of the shell variable $#, $@, $0 in linux. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are 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