在某個makefile檔案中通過include引入某個檔案進來
Include $(shell ./getname)
而getname中的內容即為:
pwd=$(pwd);
if [ "${pwd#*/zloader.}" = "$pwd" ];then
echo Makefile.cpci
else
echo Makefile.${pwd#*/zloader.}
fi
一直沒看懂${pwd#*/zloader.} 這個代表什麼意思,後來才知道其實得到的是Make file檔案的尾碼名。
如果是pwd= /xxx/yyy/zloader.bios,那麼需要得到的是Makefile.bios,其中 ${pwd#*/zloader.} = bios。其中${aaa#bbb}是一個Regex,而'*/ '表示pwd中路徑字串中zloader前面的全部部分。
解釋:
${parameter#pattern}
Substitute the value of parameter with patternremoved from the left side. The smallest portion of the contents of parametermatching pattern is removed. Shell filename substitution characters (*, ?,[...], !, and @) may be used in pattern.
在Linux下嘗試一下指令碼,即可證明。
#!/bin/sh
mkdir -p zloader./xxdir
cd zloader./xxdir
pwd=$(pwd)
echo "pwd = $pwd"
echo "this will substitue pwd about the patternzloader. , into NULL"
echo "${pwd#*/zloader.}"
cd ../..