LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1062|回复: 4

${!VARIABLE}这种结构是什么意思,实在是查不到啊

[复制链接]
发表于 2007-9-17 22:59:35 | 显示全部楼层 |阅读模式
BLFS中 /etc/profile 的代码:

cat > /etc/profile << "EOF"
# Begin /etc/profile
# Written for Beyond Linux From Scratch
# by James Robertson <jameswrobertson@earthlink.net>
# modifications by Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg>

# System wide environment variables and startup programs.

# System wide aliases and functions should go in /etc/bashrc.  Personal
# environment variables and startup programs should go into
# ~/.bash_profile.  Personal aliases and functions should go into
# ~/.bashrc.

# Functions to help us manage paths.  Second argument is the name of the
# path variable to be modified (default: PATH)
pathremove () {
        local IFS=':'
        local NEWPATH
        local DIR
        local PATHVARIABLE=${2:-PATH}
        for DIR in ${!PATHVARIABLE} ; do
                if [ "$DIR" != "$1" ] ; then
                  NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
                fi
        done
        export $PATHVARIABLE="$NEWPATH"
}

pathprepend () {
        pathremove $1 $2
        local PATHVARIABLE=${2:-PATH}
        export $PATHVARIABLE="$1${!PATHVARIABLE:+{!PATHVARIABLE}}"
}

pathappend () {
        pathremove $1 $2
        local PATHVARIABLE=${2:-PATH}
        export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}


# Set the initial path
export PATH=/bin:/usr/bin

if [ $EUID -eq 0 ] ; then
        pathappend /sbin:/usr/sbin
        unset HISTFILE
fi

# Setup some environment variables.
export HISTSIZE=1000
export HISTIGNORE="&:[bf]g:exit"
#export PS1="[\u@\h \w]\\$ "
export PS1='\u@\h:\w\$ '

for script in /etc/profile.d/*.sh ; do
        if [ -r $script ] ; then
                . $script
        fi
done

# Now to clean up
unset pathremove pathprepend pathappend

# End /etc/profile
EOF
发表于 2007-9-18 08:55:31 | 显示全部楼层
man bash, then search for 'Parameter Expansion'.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-9-18 12:14:36 | 显示全部楼层
手册中只有这两种:
${!prefix*}
${!prefix@}
   Expands to the names of variables whose names begin with prefix, separated by the first character of the IFS special variable.

${!name[@]}
${!name
  • }
      If name is an array variable,  expands  to  the  list  of  array indices  (keys)  assigned  in  name.   If  name is not an array, expands to 0 if name is set and null otherwise.  When @ is  used and the expansion appears within double quotes, each key expands to a separate word.

    可是这句:
    export ATHVARIABLE="$1${!PATHVARIABLE:+{!PATHVARIABLE}}"
    里面没有“@”与“*”符号,又怎么解释?
  • 回复 支持 反对

    使用道具 举报

    发表于 2007-9-19 20:57:07 | 显示全部楼层
    回复 支持 反对

    使用道具 举报

    发表于 2007-9-19 21:04:38 | 显示全部楼层
    这个是间接引用,像指针(当然不是)

    try: a=b b=c echo ${!a}
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    快速回复 返回顶部 返回列表