4

$の意味は何ですか!シェルまたはシェルスクリプトで?次のようなスクリプトを理解しようとしています。

local@usr> a=1
local@usr> echo $a
1
local@usr> echo $!a
a

変数を出力し直しています。それで全部ですか?私たちが持っている他の$xオプションは何ですか?$$、$ *、$?を知っている人はほとんどいません。誰かが私に良い情報源を教えてくれるなら、それは役に立ちます。ところで、これはSun OS 5.8、KSHにあります。

4

5 に答える 5

6
于 2009-11-04T10:38:52.113 に答える
2

ksh私のシステムのマニュアルページから:

  $ {!vname}
      vnameによって参照される変数の名前に展開されます。これ
      vnameが名前参照である場合を除いて、vnameになります。
于 2009-11-04T10:38:17.853 に答える
1

For the shell you are asking, ksh, use the the ksh manual, and read this:

Parameter Substitution
A parameter is an identifier, one or more digits, or any of the characters *, @, #, ?, -, $, and !.

It is clear that those are the accepted options $*, $@, $#, $?, $-, $$, and $!.
More could be included in the future.


For the parameter $!, from the manual:

"!" The process number of the last background command invoked.

if you start a background process, like sleep 60 &, then there will be a process number for such process, and the parameter $! will print its number.

$ sleep 60 &
[1] 12329
$ echo "$!"
12329

If there is no background process in execution (as when the shell starts), the exansion is empty. It has a null value.

$ ksh -c 'echo $!'

If there is a background process, it will expand to the PID of such process:

$  ksh -c 'sleep 30 & echo $!'
42586

That is why echo $!a expanded to a. It is because there is no PID to report:

$  ksh -c 'echo $!a'
a

Other shells may have a different (usually pretty similar) list of expansions (a parameter with only one $ and one next character).
For example, bash recognize this *@#?-$!0_ as "Special parameters". Search the Bash manual for the heading "3.4.2 Special Parameters".

Special Parameters
The shell treats several parameters specially.

于 2015-10-30T14:14:09.437 に答える
0

It gives the Process id of last backgroundjob or background function Please go through this link below

http://www.well.ox.ac.uk/~johnb/comp/unix/ksh.html#specvar
于 2009-12-07T11:14:36.037 に答える
0

! is a reference operator in unix, though it is not called with that name.

It always refers to a mother process. Try typing :! in vi, it takes you to command prompt and you can execute commands as usual until exit command.

! in SQLPLUS also executes the command from the command prompt. try this in sqlplus

SQL> !ls --- this gives the list of files inthe current dir.

$! - obviously gives the process id of the current/latest process.

于 2009-12-13T08:37:11.193 に答える