zoukankan      html  css  js  c++  java
  • 常用的一些shell变量

    $0 $1 表示第几个参数,在awk中以$1开始计

    $# 参数个数

    $* 所有位置参数作为一个单词

    $@ 与$*同义,但每一个参数都是一个独立的“引用字符串”,推荐使用$@

    $_ 之前执行的命令的最后一个参数

    $? 命令、函数或者脚本本身的退出状态

    $$ 脚本自身的PID,可用于构造一个“unique”的临时文件名

    示例:

    test.sh:

    echo "the total number of parameters is $#"
    echo "the name of shell file is $0"
    echo "the total parameters using $*: $*"
    echo "the total parameters using $@: $@"
    echo "arg in "$*""
    for arg in "$*"
    do
        echo $arg
    done
    
    echo "arg in "$@""
    for arg in "$@"
    do
        echo $arg
    done
    
    echo "the last parameter is $_"
    echo "the shell pid id $$"

    运行:chmod 777 test.sh ; ./test.sh one two three

    输出:

    the total number of parameters is 3
    the name of shell file is ./test.sh
    the total parameters using $*: one twothree
    the total parameters using $@: one twothree
    arg in "$*"
    one two three
    arg in "$@"
    one
    two
    three
    the last parameter is three
    theshell pid id 27635


  • 相关阅读:
    [cf582E]Boolean Function
    [atAGC029F]Construction of a tree
    [atAGC020E]Encoding Subsets
    [gym102769L]Lost Temple
    [atAGC034E]Complete Compress
    [cf566E]Restoring Map
    [atAGC023F]01 on Tree
    [gym102822I]Invaluable Assets
    [gym102900H]Rice Arrangement
    [Offer收割]编程练习赛32
  • 原文地址:https://www.cnblogs.com/OpenLinux/p/5020692.html
Copyright © 2011-2022 走看看