9.1. Internal Variables

9.1. Internal Variables

1、不懂:


$DIRSTACK

    the top value in the directory stack (affected by pushd and popd)

    This builtin variable corresponds to the dirs command, however dirs shows

    the entire contents of the directory stack.

2、

 


$EUID

    "effective" user ID number

    Identification number of whatever identity the current user has assumed,

    perhaps by means of su.

    Caution The $EUID is not necessarily the same as the $UID.

3、


  $GLOBIGNORE

    A list of filename patterns to be excluded from matching in globbing.

4、


     root# echo ${GROUPS[1]}

     1

5、


    $IFS defaults to whitespace (space, tab, and newline), but may be changed,

    for example, to parse a comma-separated data file. Note that $* uses the

    first character held in $IFS. See Example 5-1.

     bash$ echo $IFS | cat -vte

     $

     bash$ bash -c 'set w x y z; IFS=":-;"; echo "$*"'

     w:x:y:z

6、IFS是空格时,字符间的多个空格视为一个分隔符,第一个字符前面的空格会忽略不计。见例子ifs.sh。


              14 IFS=" "

              15 var=" a  b c   "

 ...

              26 IFS=:

              27 var=":a::b:c:::"               # Same as above, but substitute

运行结果:


[mdx@localhost abs-exercises]$ ./ex9-1.sh

IFS=" "

-------

the arg is: [a]

the arg is: [b]

the arg is: [c]

IFS=:

-----

the arg is: []

the arg is: [a]

the arg is: []

the arg is: [b]

the arg is: [c]

the arg is: []

the arg is: []

[mdx@localhost abs-exercises]$

7、$LINENO 不懂


$LINENO

    This variable is the line number of the shell script in which this

variable

    appears. It has significance only within the script in which it appears,

    and is chiefly useful for debugging purposes.

       1 # *** BEGIN DEBUG BLOCK ***

       2 last_cmd_arg=$_  # Save it.

       3

       4 echo "At line number $LINENO, variable \"v1\" = $v1"

       5 echo "Last command argument processed = $last_cmd_arg"

       6 # *** END DEBUG BLOCK ***

8、$PIPESTATUS不懂,并且在本机上的执行结果与书中的不同


     bash$ echo $PIPESTATUS

     0

     bash$ ls -al | bogus_command

     bash: bogus_command: command not found

     bash$ echo $PIPESTATUS

     141

     bash$ ls -al | bogus_command

     bash: bogus_command: command not found

     bash$ echo $?

     127

...

          bash$ echo ${PIPESTATUS[@]}

9、不懂

$PWD的:


      22 # rm -f .[^.]* ..?*   to remove filenames beginning with multiple

dots.      23 # (shopt -s dotglob; rm -f *)   will also work.

      24 # Thanks, S.C. for pointing this out.

10、不懂$SHELLOPTS的用法


[mdx@localhost abs-exercises]$ echo $SHELLOPTS

braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor

11、$SHLVL的用法


$SHLVL

    Shell level, how deeply Bash is nested. If, at the command line, $SHLVL is

    1, then in a script it will increment to 2.

12、$TMOUT的用法不懂,例子example9-2~9-4不懂

13、$UID,下面这段话的意思不懂

This is the current user's real id, even if she has temporarily assumed

    another identity through su.

14、example9-7太复杂了,留在这里备忘


    Caution The $* and $@ parameters sometimes display inconsistent and

            puzzling behavior, depending on the setting of $IFS.

    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

    Example 9-7. Inconsistent $* and $@ behavior

15、set命令的用法


[mdx@localhost abs-exercises]$ set a b c

[mdx@localhost abs-exercises]$ echo $1 $2 $3

a b c

[mdx@localhost abs-exercises]$

16、$!的用法

书上的例子:

LOG=$0.log

COMMAND1="sleep 100"

echo "Logging PIDs background commands for script: $0" >> "$LOG"

# So they can be monitored, and killed as necessary.

echo >> "$LOG"

# Logging commands.

echo -n "PID of \"$COMMAND1\":  " >> "$LOG"

${COMMAND1} &

echo $! >> "$LOG"

# PID of "sleep 100":  1506

# Thank you, Jacques Lederer, for suggesting this.

#下面这句不大懂:eval, kill -9

#possibly_hanging_job & { sleep ${TIMEOUT}; eval 'kill -9 $!' &> /dev/null; }      

# Forces completion of an ill-behaved program.

# Useful, for example, in init scripts.

# Thank you, Sylvain Fourmanoit, for this creative use of the "!" varia

英语疑问:

1、subtleties, nuances

This requires learning their subtleties and nuances.

2、necessarily

$SHELL does not necessarily give the correct answer.

3、collation order, mishandled

$LC_COLLATE

    Often set in the .bashrc or /etc/profile files, this variable controls

    collation order in filename expansion and pattern matching. If mishandled,

    LC_COLLATE can cause unexpected results in filename globbing.

4、revert, customary

To revert to the customary behavior of bracket matching, set LC_COLLATE to C by an export LC_COLLATE=C in /etc/profile and/or ~/.bashrc.

5、expedient

In a script, it may be expedient to temporarily add a directory to the path

    in this way.

6、likewise

         $SHELL, the name of the user's login shell, may be set from /

         etc/passwd or in an "init" script, and it is likewise not a

         Bash builtin.