zoukankan      html  css  js  c++  java
  • Linux:变量$#,$@,$0,$1,$2,$*,$$,$?

    写一个简单的脚本

     vim var

    脚本内容如下:

    #!/bin/sh
    echo "the number of parameters passed to the script: $#"
    echo "the name of the script itself: $0"
    echo "the first parameter passed to the shell script: $1"
    echo "the second parameter passed to the shell script: $2"
    echo "the list of all the parameters passed to the script(some string): $@"
    echo "the list of all the parameters passed to the script(one string): $*"
    echo "the current process ID number of the script which is running: $$"
    echo "the return value of the last shell command performed: $?"
    保存退出。
     
    赋予脚本执行权限:
     chmod +x var

    执行脚本:

    # ./var i j k
    the number of parameters passed to the script: 3
    the name of the script itself: ./var
    the first parameter passed to the shell script: i
    the second parameter passed to the shell script: j
    the list of all the parameters passed to the script(some string): i j k
    the list of all the parameters passed to the script(one string): i j k
    the current process ID number of the script which is running: 3746
    the return value of the last shell command performed: 0

    通过显示结果可以看到:

    $# 是传递给脚本的参数个数;
    $0 是脚本本身的名字;
    $1 是传递给该shell脚本的第一个参数;
    $2 是传递给该shell脚本的第二个参数;
    $@ 是传递给脚本的所有参数的列表(是多个字符串,每个参数为1个字符串);
    $* 是传递给脚本的所有参数的列表(以一个单字符串显示所有参数),与位置变量不同,参数可超过9个;
    $$ 是运行脚本的当前进程ID号;
    $? 是显示执行上一条Shell命令的返回值,0表示没有错误,其他表示有错误。
  • 相关阅读:
    Selenium Webdriver 自动化测试开发常见问题(C#版)VS
    HTML 和 Body 在 CSS 中的区别
    安装SDK时出现Fetching https://dl-ssl.google.com/android/repository/addons_list-1.xml
    配置好Java和SDK的环境变量后,Javac不是内部命令
    关于adb连接手机offline的问题解决
    CSDN上总结的测试工具排名
    关于性能优化
    关于WAS_1
    IIS服务器搭建
    关于WAS
  • 原文地址:https://www.cnblogs.com/xwb583312435/p/9049753.html
Copyright © 2011-2022 走看看