zoukankan      html  css  js  c++  java
  • shell脚本中变量$$、$0等的含义

    $0 这个程式的执行名字
    $n 这个程式的第n个参数值,n=1..9
    $* 这个程式的所有参数,此选项参数可超过9个。
    $# 这个程式的参数个数
    $$ 这个程式的PID(脚本运行的当前进程ID号)
    $! 执行上一个背景指令的PID(后台运行的最后一个进程的进程ID号)
    $? 执行上一个指令的返回值 (显示最后命令的退出状态。0表示没有错误,其他任何值表明有错误)
    $- 显示shell使用的当前选项,与set命令功能相同
    $@ 跟$*类似,但是可以当作数组用

    示例:

    1 #!/bin/bash
     2 #
     3 printf "The complete list is %s " "$$"
     4 printf "The complete list is %s " "$!"
     5 printf "The complete list is %s " "$?"
     6 printf "The complete list is %s " "$*"
     7 printf "The complete list is %s " "$@"
     8 printf "The complete list is %s " "$#"
     9 printf "The complete list is %s " "$0"
    10 printf "The complete list is %s " "$1"
    11 printf "The complete list is %s " "$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
     
  • 相关阅读:
    请简单介绍spring支持的常用数据库事务传播属性和事务隔离级别
    Spring Bean的作用域
    成员变量与局部变量的区别
    递归与迭代
    方法参数的传递机制 ---- 值传递
    windows phone 动画 当子控件超出父控件返回时
    把dataset 输出到 excel
    代码段
    c++ 学习纪录
    做自己的代码生成器
  • 原文地址:https://www.cnblogs.com/ph829/p/4739320.html
Copyright © 2011-2022 走看看