linux中shell变量$#,$@,$*,$?,$$,$!,$_,$0,$1,$2的含义解释

时间:2023-03-09 05:42:25
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 ~]$ bashparams.sh 123456 QQ
   The complete listis24249
   The complete listis 
   The complete listis0
   The complete listis123456 QQ
   The complete listis123456
   The complete listisQQ
   The complete listis2
   The complete listisparams.sh
   The complete listis123456
   The complete listisQQ
   Have a nice day!!!

随机推荐

  1. Linux运维

    概要:http://os.51cto.com/art/201312/423616.htm 论坛: http://www.linux360.cn/ https://www.centos.bz/ http ...

  2. nested exception is org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 56; cvc-complex-type.2.4.c通配符的匹配很全面, 但无法找到元素 'dubbo:application' 的声明

    严重: Exception sending context initialized event to listener instance of class org.springframework.we ...

  3. Java for LeetCode 198 House Robber

    You are a professional robber planning to rob houses along a street. Each house has a certain amount ...

  4. Linux/Ubuntu下解压命令

    .tar 解包:tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) ——————————————— .gz 解压 ...

  5. Thread源码分析

    本文为转载,请珍惜别人的劳动成果,注明转载地址:http://www.cnblogs.com/gw811/archive/2012/10/15/2724602.html 1.Runnable接口源码: ...

  6. August 5th, 2016, Week 32nd, Friday

    Life is made up of small pleasures. 生活由各种细小的幸福构成. Don't expect too much. I am not qualified to get m ...

  7. Android ViewHolder工具

    import android.util.SparseArray; import android.view.View; /** * 封装了setTag()和getTag()方法 * 封装了findVie ...

  8. Linux下的原子操作

    linux支持的哪些操作是具有原子特性的?知道这些东西是理解和设计无锁化编程算法的基础. __sync_fetch_and_add系列的命令,发现这个系列命令讲的最好的一篇文章,英文好的同学可以直接去 ...

  9. ytu 1985:C语言实验——保留字母(水题)

    C语言实验——保留字母 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 136  Solved: 59[Submit][Status][Web Board] ...

  10. hive笔记(自学整理的)

    第一部分:用户管理 创建用户:CREATE DATABASE XXX 查看用户:SHOW DATABASES; 关键查看用户:show databases like 'de.*'   讲解:创建一个用 ...