這個腳本檢查一個目錄是另一個父目錄。如何工作這個腳本?什麼是=〜在下面的腳本
T() {
if [[ "$2" =~ ${1}['/'?] ]] ; then
echo "$2 is child of $1"
return 0
else
echo "$2 is NOT child of $1 ($?)"
return 1
fi
}
這個腳本檢查一個目錄是另一個父目錄。如何工作這個腳本?什麼是=〜在下面的腳本
T() {
if [[ "$2" =~ ${1}['/'?] ]] ; then
echo "$2 is child of $1"
return 0
else
echo "$2 is NOT child of $1 ($?)"
return 1
fi
}
從手冊:
An additional binary operator, ‘=~’, is available, with the same precedence as ‘==’ and ‘!=’. When
it is used, the string to the right of the operator is considered an extended regular expression
and matched accordingly (as in regex3)). The return value is 0 if the string matches the pattern,
and 1 otherwise.
這是一個正則表達式匹配,一個將字符串與模式匹配的有用工具。 This link可能會幫助你。
它是一個正則表達式模式匹配運算符。請參閱Conditional constructs下的bash
參考手冊 - 並查找[[ ... ]]
結構。
閱讀['bash'手冊頁](http://linux.die.net/man/1/bash)。 –
你的問題含糊不清。你想知道這個腳本是如何工作的 - 特別是'〜='在做什麼,或者如何使用這個腳本?請澄清一下。 –
爲了避免混淆這裏發生的事情,[我們自由地對這個問題做了一些實驗](http://meta.stackexchange.com/questions/192242/you-made-too-few-changes-to-在-後對提高-它)。 – Bobby