shell变量$#,$@,$0,$1,$2的含义
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参数…。
示例:
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
结果:
[Aric@localhost ~]$ bash params.sh 123456 QQ
The complete list is 24249
The complete list is
The complete list is 0
The complete list is 123456 QQ
The complete list is 123456
The complete list is QQ
The complete list is 2
The complete list is params.sh
The complete list is 123456
The complete list is QQ
Have a nice day!!!
转载:http://www.jb51.net/article/108715.htm
随机推荐
- widows终端远程连接Linux服务器
一.前言 为什么不是远程连接Linux服务器? 因为我不会,远程连接window我就用电脑自带的“远程桌面连接”. 以下所述都是在CentOS操作系统下的. 服务器刚换成Linux的时候很迷茫,感觉无 ...
- BZOJ3240 NOI2013矩阵游戏(数论)
必修五题. // luogu-judger-enable-o2 #include<iostream> #include<cstdio> #include<cmath> ...
- [BZOJ3295][Cqoi2011]动态逆序对 CDQ分治&树套树
3295: [Cqoi2011]动态逆序对 Time Limit: 10 Sec Memory Limit: 128 MB Description 对于序列A,它的逆序对数定义为满足i<j,且 ...
- HBase介绍及简易安装
HBase简介 HBase是Apache Hadoop的数据库,能够对大型数据提供随机.实时的读写访问,是Google的BigTable的开源实现.HBase的目标是存储并处理大型的数据,更具体地说仅 ...
- 【AGC003F】Fraction of Fractal
Description 原题链接 Solution 神题. 定义一个上边界或下边界的格子为"上下接口",当且仅当上下边界该位置的格子都是黑色的. "左 ...
- 【Learning】辛普森积分
辛普森积分 这种积分法很暴力:只要求你实现出函数求值\(f(x)\). 使用辛普森积分,我们可以求出函数一段区间\([l,r]\)的近似积分.记\(mid=\frac{l+r}2\),有: \[ \i ...
- 【bzoj1078】 SCOI2008—斜堆
http://www.lydsy.com/JudgeOnline/problem.php?id=1078 (题目链接) 题意 给出一个斜堆,并给出其插入的操作,求一个字典序最小的插入顺序. Solut ...
- 破解PostgresSQL登录的6种方法
第一种方式Hydra: Hydra通常是首选工具,它可以对50多种协议执行快速字典暴力攻击,包括telnet,postgres,http,https,smb服务和各种数据库等.现在需要选择一个字典 ...
- debian8安装harbor
这里的系统版本是debian8.8,harbor版本为1.1.2. 1.安装docker-ce 1.1.Install packages to allow apt to use a repositor ...
- 项目开发中git常用命令、git工作流、git分支模型
#新建代码库git init # 在当前目录新建一个Git代码库git init [project-name] # 新建一个目录,将其初始化为Git代码库git clone [url] # 下载一个项 ...