惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
O
OpenAI News
S
Secure Thoughts
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
S
Security Affairs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
The Register - Security
The Register - Security
GbyAI
GbyAI
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Cloudflare Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
V
V2EX
T
Tailwind CSS Blog
SecWiki News
SecWiki News
NISL@THU
NISL@THU
C
Check Point Blog

博客园 - hunter_gio

用xargs处理带空格文件名 利用awk分割电子书大文件 推荐几本Python电子书 学习Shell好书 C/C++ 电子书推荐 Unicode5.1版发布 GB18030编码研究以及GBK、GB18030与Unicode的映射[转] Unicode、GB2312、GBK和GB18030中的汉字[转] 中日韩统一表意文字(CJK Unified Ideographs)[转] Unicode介绍[转] simple usage of tcpdump Python语言浅议 巴菲特:我的工作是阅读 我喜欢的Ubuntu软件列表 del.icio.us导出到google书签 解决w950播放RM视频的问题[转] Python 3.0a1 Release [Ebook]The Definitive Guide to SQLite ORACLE----触发器,存储过程及JOB
linux中shell变量$#,$@,$0,$1,$2的含义解释
hunter_gio · 2012-08-15 · via 博客园 - hunter_gio

linux中shell变量$#,$@,$0,$1,$2的含义解释: 

变量说明: 

$$ 

Shell本身的PID(ProcessID) 

$! 

Shell最后运行的后台Process的PID 

$? 

最后运行的命令的结束代码(返回值) 

$- 

使用Set命令设定的Flag一览 

$* 

所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。 

$@ 

所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。 

$# 

添加到Shell的参数个数 

$0 

Shell本身的文件名 

$1~$n 

添加到Shell的各参数值。$1是第1参数、$2是第2参数…。 

我们先写一个简单的脚本,执行以后再解释各个变量的意义 

# touch variable 

# vi variable 

脚本内容如下: 

#!/bin/sh 

echo "number:$#" 

echo "scname:$0" 

echo "first :$1" 

echo "second:$2" 

echo "argume:$@" 

保存退出 

赋予脚本执行权限 

# chmod +x variable 

执行脚本 

# ./variable aa bb 

number:2 

scname:./variable 

first: aa 

second:bb 

argume:aa bb 

通过显示结果可以看到: 

$# 是传给脚本的参数个数 

$0 是脚本本身的名字 

$1是传递给该shell脚本的第一个参数 

$2是传递给该shell脚本的第二个参数 

$@ 是传给脚本的所有参数的列表

===================================

For understanding the diffrence of $* and $@ try the following script 
for x in "$*" 
do 

echo $x 
done 

for x in "$@" 
do 
echo $x 
done 

If the script is t1.sh, execute the same as 
#./t1.sh London Paris Newyork