当前位置:网站首页>基于arm5718的Shell脚本参数传递的2种方法
基于arm5718的Shell脚本参数传递的2种方法
2022-06-28 03:23:00 【毛毛虫的爹】
前言
平时会遇到很多脚本都有参数选项,类似:
./test.sh -f config.conf -v --prefix=/home
这种脚本怎么写呢?
一、Shell 特殊参数解释
首先来看几个特殊变量:$0, $#, $*, [email protected], $?, $$, $_
示例1:新建一个test.sh的文件
#!/bin/bash
echo $0 # 当前脚本的文件名(间接运行时还包括绝对路径)。
echo $n # 传递给脚本或函数的参数。n 是一个数字,表示第几个参数。例如,第一个参数是 $1 。
echo $# # 传递给脚本或函数的参数个数。
echo $* # 传递给脚本或函数的所有参数。
echo [email protected] # 传递给脚本或函数的所有参数。被双引号 (" ") 包含时,与 $* 不同,下面将会讲到。
echo $? # 上个命令的退出状态,或函数的返回值。
echo $$ # 当前 Shell 进程 ID。对于 Shell 脚本,就是这些脚本所在的进程 ID。
echo $_ # 上一个命令的最后一个参数
echo $! # 后台运行的最后一个进程的 ID 号
执行结果如下:
$ ./test.sh test test1 test2 test3 test4
./test.sh # $0
# $n
5 # $#
test test1 test2 test3 test4 # $*
test test1 test2 test3 test4 # [email protected]
0 # $?
12305 # $$
12305 # $_
# $!
$* 和 [email protected] 都表示传递给函数或脚本的所有参数
边栏推荐
- Resource management, high availability and automation (medium)
- How to modify a se38 editor theme
- 解析STEAM教育框架下未来教师研究能力
- vscode中出现无法在只读编辑器中编辑
- Automatic backup of MySQL database
- What is the core problem to be solved in the East and West?
- 指针链表
- 上线MES系统后,企业发生了这些变化......
- Chapter 1 Introduction to bash
- Li Kou daily question - day 29 -575 Divide candy
猜你喜欢
"Five layer" architecture of cloud applications and services
PyCharm设置仿sublime配色方案
[graduation season] graduate summary
English语法_形容词/副词3级-比较级_常用短语
数据库系列之MySQL配置F5负载均衡
leetcode:单调栈结构(进阶)
Several ways of sharing printers in LAN
工业物联网将取代人工发展吗?
第一个.net core MVC项目
django. core. exceptions. ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
随机推荐
Research and arrangement of electronic map coordinate system
leetcode:单调栈结构(进阶)
月赛补题
How to write anti shake throttling for small programs?
图片的懒加载和预加载
解析教育机器人的综合应用能力
Does the applet image component not display pictures?
解析STEAM教育框架下未来教师研究能力
Cannot edit in read-only editor if it appears in vscode
数字有为,易步到位 华为携“5极”明星产品加速布局商业市场
黑体辐射初探
English notes - cause and effect
加法器—笔记
Pycharm setting pseudo sublime color scheme
MySQL error
A solution to the inefficiency of setting debug mode in developing flask framework with pychar
一文告诉你什么是 Kubernetes
如何系统学习一门编程语言? | 黑马程序员
第14章 AC-DC电源前级电路 笔记一
No  result  defined& nbsp…