美文网首页
Linux shell中的$0-$n,$$,$!,$?...

Linux shell中的$0-$n,$$,$!,$?...

作者: yywfy的昵称 | 来源:发表于2018-09-28 10:42 被阅读0次

    变量说明

    $$:Shell本身那个的PID(ProcessID)

    $!:Shell最后运行的后台Process的PID

    $?:Shell最后运行的命令的结束代码(返回值)

    $-:使用Set命令设定的Flag列表

    $*:输出Shell所有参数列表;用引号括起来"$*"会以"$1 $2 ... $n"的形式输出所有参数

    $@:输出Shell所有参数列表;用引号括起来"$@"会以"$1" "$2" ..."$n"的形式输出所有参数

    $#:添加到Shell的参数个数

    $0:Shell脚本的文件名

    $1~$n:Shell脚本的第1个到第n个输入参数


    脚本例子:test

    # !/bin/sh

    echo "number:$#"

    echo "script_name:$0"

    echo "first_arg:$1"

    echo "second_arg:$2"

    echo  "arg_list:$@"

    #./test aa bb

    number:2

    script_name:./test

    first_arg:aa

    second_arg:bb

    arg_list:aa bb

    相关文章

      网友评论

          本文标题:Linux shell中的$0-$n,$$,$!,$?...

          本文链接:https://www.haomeiwen.com/subject/kmpuoftx.html