博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
常用的一些shell变量
阅读量:4461 次
发布时间:2019-06-08

本文共 854 字,大约阅读时间需要 2 分钟。

$0 $1 表示第几个参数,在awk中以$1开始计

$# 参数个数

$* 所有位置参数作为一个单词

$@ 与$*同义,但每一个参数都是一个独立的“引用字符串”,推荐使用$@

 

$_ 之前执行的命令的最后一个参数

$? 命令、函数或者脚本本身的退出状态

$$ 脚本自身的PID,可用于构造一个“unique”的临时文件名

示例:

test.sh:

echo "the total number of parameters is $#"echo "the name of shell file is $0"echo "the total parameters using \$*: $*"echo "the total parameters using \$@: $@"echo "arg in \"\$*\""for arg in "$*"do    echo $argdoneecho "arg in \"\$@\""for arg in "$@"do    echo $argdoneecho "the last parameter is $_"echo "the shell pid id $$"

运行:chmod 777 test.sh ; ./test.sh one two three

输出:

the total number of parameters is 3the name of shell file is ./test.shthe total parameters using $*: one twothreethe total parameters using $@: one twothreearg in "$*"one two threearg in "$@"onetwothreethe last parameter is threetheshell pid id 27635

转载于:https://www.cnblogs.com/OpenLinux/p/5020692.html

你可能感兴趣的文章
Palindromes _easy version
查看>>
vue 小记
查看>>
CURRICULUM VITAE
查看>>
菱形缓冲器电路
查看>>
Groovy 程序结构
查看>>
使用 WordPress 的导航菜单
查看>>
input只能输入数字和小数点,并且只能保留小数点后两位 - CSDN博客
查看>>
js 不固定传参
查看>>
远程调试UWP遇到新错误Could not generate the root folder for app package ......
查看>>
[倍增][最短路-Floyd][dp]
查看>>
SpringAOP用到了什么代理,以及动态代理与静态代理的区别
查看>>
利用STM32CubeMX来生成USB_HID_Mouse工程【添加ADC】(1)
查看>>
【leetcode】Populating Next Right Pointers in Each Node
查看>>
获取请求参数乱码的问题
查看>>
代码实现:判断E盘目录下是否有后缀名为.jpg的文件,如果有,就输出该文件名称...
查看>>
Android客户端测试点
查看>>
Jquery:怎样让子窗体的div显示在父窗体之上
查看>>
01概率
查看>>
Shell脚本
查看>>
MatLab Load cv::Mat 导入数据
查看>>