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

  • 相关阅读:
    11
    消除左递归
    4.K均值算法--应用
    3.K均值算法
    2.机器学习相关数学基础作业
    机器算法学习第一次作业
    第十五次作业
    第十四次作业
    第十三次作业
    第十二次作业
  • 原文地址:https://www.cnblogs.com/itcomputer/p/7855976.html
Copyright © 2011-2022 走看看