不理解 bash 参数声明

Don't understand bash parameter declaration

我在阅读下面这个参数时遇到问题:

  1. 我不明白使用这个的目的$(basename "[=12=]")它是从哪里来的。

  2. ${BINARY%/*} 似乎它试图获取目录的路径,但究竟为什么只需要这样。

DIR_NAME=$(dirname "[=11=]")
FILE_NAME=$(basename "[=11=]")
BINARY=`readlink ${ROOT_DIR}/${DIR_NAME}/${FILE_NAME} -f`
BIN_PATH=${BINARY%/*}
  1. [=10=] 是脚本的路径名 运行。所以 $(dirname "[=11=]") returns 脚本的目录, $(basename "[=12=]") 是文件名。

  2. ${BINARY%/*}Shell Parameter Expansion

  3. 中有解释

${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in filename expansion. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted.

所以这会找到 $BINARY 的尾部部分匹配 /* 并将其删除,returns 目录部分。相当于 $(dirname "$BINARY")