什么是特殊的美元符号 shell 变量? [英] What are the special dollar sign shell variables?

查看:42
本文介绍了什么是特殊的美元符号 shell 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Bash 中,似乎有几个变量持有特殊的、具有一致意义的值.例如,

In Bash, there appear to be several variables which hold special, consistently-meaning values. For instance,

./myprogram &; echo $!

将返回后台myprogram的进程的PID.我知道其他的,例如 $? 我认为这是当前的 TTY.还有其他的吗?

will return the PID of the process which backgrounded myprogram. I know of others, such as $? which I think is the current TTY. Are there others?

推荐答案

  • $1, $2, $3, ... 是 位置参数.
  • "$@" 是所有位置参数的类数组结构,{$1, $2, $3 ...}.
  • "$*" 是所有位置参数的 IFS 扩展,$1 $2 $3 ....
  • $# 是位置参数的数量.
  • $- 为 shell 设置的当前选项.
  • $$ 当前shell(非子shell)的pid.
  • $_ 最近的参数(或启动后立即启动当前 shell 的命令的 abs 路径).
  • $IFS 是(输入)字段分隔符.
  • $? 是最近的前台管道退出状态.
  • $! 是最近的后台命令的 PID.
  • $0 是 shell 或 shell 脚本的名称.
    • $1, $2, $3, ... are the positional parameters.
    • "$@" is an array-like construct of all positional parameters, {$1, $2, $3 ...}.
    • "$*" is the IFS expansion of all positional parameters, $1 $2 $3 ....
    • $# is the number of positional parameters.
    • $- current options set for the shell.
    • $$ pid of the current shell (not subshell).
    • $_ most recent parameter (or the abs path of the command to start the current shell immediately after startup).
    • $IFS is the (input) field separator.
    • $? is the most recent foreground pipeline exit status.
    • $! is the PID of the most recent background command.
    • $0 is the name of the shell or shell script.
    • 以上大部分可以在特殊参数 在 Bash 参考手册中.有所有 shell 设置的环境变量.

      Most of the above can be found under Special Parameters in the Bash Reference Manual. There are all the environment variables set by the shell.

      综合索引请参见参考手册变量索引.

      这篇关于什么是特殊的美元符号 shell 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆