link=`expr "$ls" : '.*-> \(.*\)$'`

link=`expr "$ls" : '.*-> \(.*\)$'`

PRG="$0"

while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '.*/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

PRGDIR=`dirname "$PRG"`

请教下,这段代码有什么功能? 似乎觉得应该是查找路径

麻烦仔细讲解下其中的:
1. while循环中的“-h”测试的是啥子?
2. link=`expr "$ls" : '.*-> \(.*\)$'`
3. PRGDIR=`dirname "$PRG"`
先谢谢拉,我是初学者,书上找了半天也不知道什么意思








      
复制内容到剪贴板
代码:
1. File operators:

        -a FILE        True if file exists.
        -b FILE        True if file is block special.
        -c FILE        True if file is character special.
        -d FILE        True if file is a directory.
        -e FILE        True if file exists.
        -f FILE        True if file exists and is a regular file.
        -g FILE        True if file is set-group-id.
[color=red]        -h FILE        True if file is a symbolic link.[/color]
        -L FILE        True if file is a symbolic link.
        -k FILE        True if file has its `sticky' bit set.
        -p FILE        True if file is a named pipe.
        -r FILE        True if file is readable by you.
        -s FILE        True if file exists and is not empty.
        -S FILE        True if file is a socket.
        -t FD          True if FD is opened on a terminal.
        -u FILE        True if the file is set-user-id.
        -w FILE        True if the file is writable by you.
        -x FILE        True if the file is executable by you.
        -O FILE        True if the file is effectively owned by you.
        -G FILE        True if the file is effectively owned by your group.
        -N FILE        True if the file has been modified since it was last read.

2. man expr
3. man dirname