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

  • 相关阅读:
    友盟消息推送api、python sdk问题、测试demo代码
    Django的时区设置问题
    优酷视频上传api及demo代码
    git回滚线上代码
    charles的使用
    django+ajax用FileResponse文件下载到浏览器过程中遇到的问题
    scrapy框架
    几个简单的算法
    SQLAlchemy
    redis
  • 原文地址:https://www.cnblogs.com/itcomputer/p/7855976.html
Copyright © 2011-2022 走看看