Linux Shell函数

介绍

 

 

正文

$?

$?是shell变量,表示"最后一次执行命令"的退出状态.0为成功,非0为失败.切记:$?永远表示shell命令最后一次执行后的退出状态,当函数执行完毕后,如果又执行了其它命令,则$?不再表示函数执行后的状态,而表示其它命令的退出状态

 

$$ 
Shell本身的PID(ProcessID) 
$! 
Shell最后运行的后台Process的PID 
$? 
最后运行的命令的结束代码(返回值) 
$- 
使用Set命令设定的Flag一览 
$* 
所有参数列表。如"$*":"$1 $2 … $n"的形式输出所有参数。 
$@ 
所有参数列表。如"$@"以多行的形式"$1" "$2""$n" 输出所有参数。 
$# 
添加到Shell的参数个数 
$0 
Shell本身的文件名 
$1~$n 
添加到Shell的各参数值。$1是第1参数、$2是第2参数…。 

例:

vim a.sh

 #!/bin/bash
  printf "The complete list is %s\n" "$$"
  printf "The complete list is %s\n" "$!"
  printf "The complete list is %s\n" "$?"
  printf "The complete list is %s\n" "$*"
  printf "The complete list is %s\n" "$@"
  printf "The complete list is %s\n" "$#"
  printf "The complete list is %s\n" "$0"
  printf "The complete list is %s\n" "$1"
  printf "The complete list is %s\n" "$2"

 

 

总结

 

 

 

 

 

备注:

    作者:pursuer.chen

    博客:http://www.cnblogs.com/chenmh

本站点所有随笔都是原创,欢迎大家转载;但转载时必须注明文章来源,且在文章开头明显处给明链接。

《欢迎交流讨论》

posted @ 2016-07-12 10:34  pursuer.chen  阅读(526)  评论(0编辑  收藏  举报