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 is the meaning of the shell variables $#, $@, $0je "1j" 2 in linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article introduces the knowledge of "what is the meaning of shell variables $#, $@, $0 in linux". In the operation of actual cases, many people will encounter such a dilemma. Next, 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!

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.

The test.sh content is as follows:

#! / bin/bashprintf "The string is% s\ n"$$" printf "The string is% s\ n"$!"printf" The string is% s\ n "$?" printf "The string is% s\ n"$*" printf "The string is% s\ n"$@" printf "The string is% s\ n" $# "printf" The string is% s\ n "" $0 "printf" The string is% s\ n " Shell variable $# in $1 "printf" The string is% s\ n "$2" [root@cz_fbsdb500_06] # sh test.sh Im so diaoThe string is 6169The string is The string is 0The string is Im so diaoThe string is ImThe string is soThe string is diaoThe string is 3The string is test.shThe string is ImThe string is so "linux This is the end of the introduction of "what is the meaning of" $@, "what is the meaning of" 1 "? Thank you for your 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.

Share To

Servers

Wechat

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

12
Report