Linux:变量$#,$@,$0,$1,$2,$*,$$,$?
写一个简单的脚本
vim var
脚本内容如下:
#!/bin/sh
echo "the number of parameters passed to the script: $#"
echo "the name of the script itself: $0"
echo "the first parameter passed to the shell script: $1"
echo "the second parameter passed to the shell script: $2"
echo "the list of all the parameters passed to the script(some string): $@"
echo "the list of all the parameters passed to the script(one string): $*"
echo "the current process ID number of the script which is running: $$"
echo "the return value of the last shell command performed: $?"
chmod +x var
执行脚本:
# ./var i j k
the number of parameters passed to the script: 3
the name of the script itself: ./var
the first parameter passed to the shell script: i
the second parameter passed to the shell script: j
the list of all the parameters passed to the script(some string): i j k
the list of all the parameters passed to the script(one string): i j k
the current process ID number of the script which is running: 3746
the return value of the last shell command performed: 0
通过显示结果可以看到:
$# 是传递给脚本的参数个数;
$0 是脚本本身的名字;
$1 是传递给该shell脚本的第一个参数;
$2 是传递给该shell脚本的第二个参数;
$@ 是传递给脚本的所有参数的列表(是多个字符串,每个参数为1个字符串);
$* 是传递给脚本的所有参数的列表(以一个单字符串显示所有参数),与位置变量不同,参数可超过9个;
$$ 是运行脚本的当前进程ID号;
$? 是显示执行上一条Shell命令的返回值,0表示没有错误,其他表示有错误。
随机推荐
- CVAT 用户指南
用户指南 计算机视觉标注工具(CVAT)是基于 Web 为计算机视觉算法标注视频和图像的在线工具. 它的灵感来自Vatic免费的.在线的.交互式的视频注释工具. CVAT有许多强大的功能: 在关键帧之 ...
- 『学了就忘』Linux基础命令 — 37、Linux中挂载操作的相关命令
目录 1.mount命令介绍 (1)mount命令说明 (2)mount命令格式 2.mount命令示例 3.mount -a命令说明 4.-o特殊选项说明 5.exec/noexec选项说明 挂载就 ...
- grafan源码编译
下载grafana源码:https://github.com/grafana/grafana 前端: 安装node.js,安装完自带npmnpm install -g yarnyarn install ...
- Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create()
在Java中处理JSON格式的数据时,Google Gson 是个不错的选择,用起来挺方便的,也有一定灵活性.我现在工作中在参与的两个项目里都有用它.不过它在处理Date格式时有个小陷阱,在不同环境 ...
- 12组-Alpha冲刺-2/6
一.基本情况 队名:字节不跳动 组长博客:https://www.cnblogs.com/147258369k/p/15535639.html 小组人数:10人 二.冲刺概况汇报 侯钦凯 过去两天完成 ...
- [bzoj1072]排列
考虑用状压dp枚举排列,即f[i][j]表示当前状态为i,余数为j的方案数,考虑在末尾新增一个字符来转移即可,注意最后答案要除以排列组合 1 #include<bits/stdc++.h> ...
- lilypond 进阶—— 用scheme画图
lilypond的许多底层设定是通过scheme语言写的,特别是要写函数的时候. 所以了解一下scheme的作用很重要. 不幸的是,不像lilypond本身的代码,scheme代码的结果是不会直接预览 ...
- 洛谷 P6031 - CF1278F Cards 加强版(推式子+递推)
洛谷题面传送门 u1s1 这个推式子其实挺套路的吧,可惜有一步没推出来看了题解 \[\begin{aligned} res&=\sum\limits_{i=0}^ni^k\dbinom{n}{ ...
- JSOI(联合省选)2021 划水记
流水账. Day 0 18:10 去本部拿准考证,结果发现已经没有人了./ruo 敲了几份板子,很早就去睡觉了. Day 1 7:30 到 NFLS 拿到准考证,几乎没有人来.于是做起了政治作业. 然 ...
- micropython1.16官方文档转PDF
折腾了一天,终于把micropython1.16的官方文档给转成了pdf格式. 不过转换成PDF格式以后存在两点问题: 1.PDF文档有些地方的排版中有些行距没有调整好: 2.使用latex编译tex ...