浅谈linux中shell变量$#,$@,$0,$1,$2,$?的含义解释

下面小编就为大家带来一篇浅谈linux中shell变量$#,$@,$0,$1,$2的含义解释。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

摘抄自:ABS_GUIDE

下载地址:http://www.tldp.org/LDP/abs/abs-guide.pdf

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!!!

以上这篇浅谈linux中shell变量$#,$@,$0,$1,$2的含义解释就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

  • linux shell 中 2>&1的含义
  • Linux Shell中的特殊符号和含义简明总结(包含了绝大部份)
  • Shell中的变量使用小结

转载于:https://www.cnblogs.com/davidshen/p/10213229.html

最新文章

  1. 微信小程序asp服务器架设,asp写的微信小程序支付demo-服务器端是asp+mdb的
  2. 分享20个非常有用的Web开发工具和框架
  3. 检查卷位图时发现损坏怎么修复_中频弯管严密性如何测试?怎么修复中频弯管?...
  4. 18000 6c java_面向ISO18000-6C协议的无源超高频射频识别标签芯片设计
  5. 无法在只读编辑器中编辑_Mol Plant中国农科院作物科学研究所夏兰琴课题组成功利用 优化的引导基因编辑器在水稻中实现高效精准基因编辑...
  6. 第一个Verilog程序
  7. 2008江西高考0分作文
  8. 学完python能做什么-学完Python开发可以从事哪些行业?
  9. spring学习--jdbcTemplate - 增删改
  10. 【持久层】Druid简介
  11. 小米手机抓取Log教程
  12. UI设计师常用500多款字体和73款手写字体打包
  13. golang基础教程
  14. Unity-TCP-网络聊天功能(一): API、客户端服务器、数据格式、粘包拆包
  15. 电脑开机后进不了桌面怎么办
  16. 服务器里的文件删了能恢复吗,远程把服务器文件删了怎么恢复
  17. uboot下phy的工作
  18. 【历史上的今天】11 月 24 日:美国在线收购网景;太阳能光伏之父出生;HTML 2.0 发布
  19. 1763. 传球游戏
  20. RelativeLayout相对布局详解

热门文章

  1. 分布式监控系统Zabbix--使用Grafana进行图形展示
  2. 《Greenplum5.0 最佳实践》 系统监控与维护 (五)
  3. 爬取豆瓣电影储存到数据库MONGDB中以及反反爬虫
  4. linux下挂载光驱
  5. android 绘制控件,Android自定义控件绘制基本图形基础入门
  6. pb调用java webservice_PB调用各类WebService或c#程序
  7. cmake添加查找目录_cmake find_package路径详解
  8. Mybatis 与Spring整合及原理
  9. 蓝桥杯 ADV-140 算法提高 开灯游戏
  10. 蓝桥杯 ALGO-110 算法训练 字符串的展开