Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

bash - 什么是特殊的美元符号shell变量?(What are the special dollar sign shell variables?)

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

(在Bash中,似乎有几个变量具有特殊的,一致意义的值。)

For instance,

(例如,)

./myprogram &; echo $!

will return the PID of the process which backgrounded myprogram .

(将返回后面的myprogram进程的PID。)

I know of others, such as $?

(我知道别人,比如$?)

which I think is the current TTY.

(我认为是目前的TTY。)

Are there others?

(还有其他人吗?)

  ask by Z Douglas translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  • $1 , $2 , $3 , ... are the positional parameters .

    ($1$2$3 ,...是位置参数 。)

  • "$@" is an array-like construct of all positional parameters, {$1, $2, $3 ...} .

    ("$@"是所有位置参数的数组式构造, {$1, $2, $3 ...} 。)

  • "$*" is the IFS expansion of all positional parameters, $1 $2 $3 ... .

    ("$*"是所有位置参数的IFS扩展, $1 $2 $3 ...)

  • $# is the number of positional parameters.

    ($#是位置参数的数量。)

  • $- current options set for the shell.

    ($-为shell设置的当前选项。)

  • $$ pid of the current shell (not subshell).

    (当前shell的$$ pid(不是子shell)。)

  • $_ most recent parameter (or the abs path of the command to start the current shell immediately after startup).

    ($_最近的参数(或启动后立即启动当前shell的命令的abs路径)。)

  • $IFS is the (input) field separator.

    ($IFS是(输入)字段分隔符。)

  • $? is the most recent foreground pipeline exit status.

    (是最新的前台管道退出状态。)

  • $! is the PID of the most recent background command.

    (是最近的后台命令的PID。)

  • $0 is the name of the shell or shell script.

    ($0是shell或shell脚本的名称。)

Most of the above can be found under Special Parameters in the Bash Reference Manual.

(以上大部分内容可以在Bash参考手册中的特殊参数下找到。)

There are all the environment variables set by the shell .

(shell设置了所有环境变量 。)

For a comprehensive index, please see the Reference Manual Variable Index .

(有关综合索引,请参阅参考手册变量索引 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...