zoukankan      html  css  js  c++  java
  • 026_关于shell中的特殊变量$0 $n $* $@ $! $?

    一、

    $n:获取当前执行的shell脚本的第N个参数,n=1..9,当n为0时表示脚本的文件名,如果n大于9,用大括号括起来like${10}.

    $*:获取当前shell的所有参数,将所有的命令行参数视为单个字符串。
    $@:这个程序的所有参数"$1" "$2" "$3" "...",这是将参数传递给其他程序的最佳方式,因此TA会保留所有内嵌在每个参数里的任何空白。
    $#:获取当前shell命令行中参数的总个数。

    $_:代表上一个命令的最后一个参数

    eg:

    cat test.sh
    #!/bin/bash
    echo $_

    sh test.sh 1 2 3 4 5
    /bin/sh

    $!:代表最后执行的后台命令的PID

    eg:

    ➜  agent git:(master) ✗ nohup ./falcon-agent  -c  cfg.json &> var/app.log &
    [1] 76901
    ➜  agent git:(master) ✗ ps -p $!
      PID TTY           TIME CMD
    76901 ttys000    0:00.01 ./falcon-agent -c cfg.json
    ➜  agent git:(master) ✗ echo $!
    76901
    ➜  agent git:(master) ✗ ps -p $!
      PID TTY           TIME CMD
    76901 ttys000    0:00.02 ./falcon-agent -c cfg.json
    ➜  agent git:(master) ✗ echo $!
    76901

    ➜ agent git:(master) ✗ nohup sh ./test.sh &
    [2] 79469
    appending output to nohup.out
    ➜ agent git:(master) ✗ echo $!
    79469

    二、

    参考:http://www.111cn.net/sys/linux/79750.htm

  • 相关阅读:
    字符串与Unicode码的相互转换
    关于es6中的yield
    ajax请求中的6个全局事件
    用H5上传文件
    类型化数组
    git笔记-9-29
    js正则表达式验证身份证号和密码
    assertThat用法
    java产生随机数的几种方式
    jQuery之Deferred对象详解
  • 原文地址:https://www.cnblogs.com/itcomputer/p/7855976.html
Copyright © 2011-2022 走看看