bash疑问

1

if [ "${REL_FILE_NAME##*/}" = "Android.mk" -o "${REL_FILE_NAME##*/}" = "tvos.mk" ];

参考Bash Reference Manual
3.5.3 Shell Parameter Expansion

${parameter#word}
${parameter##word}
The word is expanded to produce a pattern just as in filename expansion (see Filename Expansion). If the pattern matches the beginning of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ‘#’ case) or the longest matching pattern (the ‘##’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
意思就是word扩展成匹配模式,#最短匹配,##最长匹配,首部开始匹配,返回值就是删除匹配内容剩余的值。手册写的有点啰嗦。

2

if [ ! -L $REL_FILE_PATH ]; then
    cp --parent $REL_FILE_PATH external/cy/hidiff/backup
    if [ ! "$NO_MODIFY_LIST" = "--no-modify-list" ]; then
        echo "$REL_FILE_PATH    D" >> external/cy/hidiff/diff.list
    fi
    echo "D $REL_FILE_PATH"
fi

不是符号连接
没有指定不修改modify_list

3

[[ $SUB_DIR_NUM -gt 0 ]] && mkdir -p ${REL_FILE_PATH%/*}

${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. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
手册写的太啰嗦了,就是尾部匹配,返回删除尾部匹配的部分。

参看<<高级bash脚本编程指南>>,在版本2.02的Bash中, 引入了[[ ... ]]扩展测试命令, 因为这种表现形式可能对某些语言的程序员来说更容易熟悉一些. 注意[[是一个关键字, 并不是一个命令.
Bash把[[ $a -lt $b ]]看作一个单独的元素, 并且返回一个退出状态码.
[[ ]]结构比[ ]结构更加通用. 这是一个扩展的test命令, 是从ksh88中引进的.
在[[和]]之间所有的字符都不会发生文件名扩展或者单词分割, 但是会发生参数扩展和命令替换.
使用[[ ... ]]条件判断结构, 而不是[ ... ], 能够防止脚本中的许多逻辑错误. 比如,&&, ||, <, 和> 操作符能够正常存在于[[ ]]条件判断结构中, 但是如果出现在[ ]结构中的话, 会报错.
参考manual
Return a status of 0 or 1 depending on the evaluation of the conditional expression expression. Expressions are composed of the primaries described below in Bash Conditional Expressions. Word splitting and filename expansion are not performed on the words between the [[ and ]]; tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process substitution, and quote removal are performed. Conditional operators such as ‘-f’ must be unquoted to be recognized as primaries.

原文地址:https://www.cnblogs.com/fedorayang/p/7106578.html