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表示没有错误,其他表示有错误。
  • 相关阅读:
    C#UDP编程总结
    C# TcpListener的编程要点
    三维地图添加切片“lods of null”报错
    三维地图添加切片图层坐标系报错
    03 三维地图添加切片图层
    从ArcMap 10.6.1发布服务到Portal,服务器地址错误
    19 React——Ant Design(按需加载样式文件)
    20 React项目生成及部署
    18 React——Ant Design的使用
    17 React——路由的模块化及嵌套
  • 原文地址:https://www.cnblogs.com/xwb583312435/p/9049753.html
Copyright © 2011-2022 走看看