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

推荐订阅源

W
WeLiveSecurity
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
S
SegmentFault 最新的问题
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
U
Unit 42
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
H
Help Net Security
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
博客园 - 聂微东
S
Securelist
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos 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