bash中的[test]和[[test]]有什麼區別? 什麼時候比另一個更合適,最後是;
?bash中的[test]和[[test]]有什麼區別?
if [[ -z $DIRECTORY ]];
then
DIRECTORY=html
fi
if [ ! -d "$DIRECTORY" ]; then
echo installation directory "'${DIRECTORY}'" does not exist
exit 1
fi
bash中的[test]和[[test]]有什麼區別? 什麼時候比另一個更合適,最後是;
?bash中的[test]和[[test]]有什麼區別?
if [[ -z $DIRECTORY ]];
then
DIRECTORY=html
fi
if [ ! -d "$DIRECTORY" ]; then
echo installation directory "'${DIRECTORY}'" does not exist
exit 1
fi
[[
類似於(但比更強大的)的命令[
一個bash關鍵字。請參閱http://mywiki.wooledge.org/BashFAQ/031和http://mywiki.wooledge.org/BashGuide/TestsAndConditionals除非您正在爲POSIX sh編寫代碼,否則我們推薦使用[[
。
'/ bin/['在功能上也等同於'/ usr/bin/test'。 –
我們通常使用單一的方括號,當我們:
if [ -L $file ]; then
if [ $a -lt $b ]; then
" "
和治療特殊字符爲正常(如星號):if [ -z "$string" ]; then
我們通常雙方括號,當我們:
if [[ "$string1" == *[sS]tring* ]]; then
if [[ -a *.sh ]]; then
if [[ $a == 3 || $b == 4]]; then
" "
[
是外殼,[[
是對於bash 。
例如:
嘗試[ $A -eq 1 ]
:如果$A
沒有設置,它拋出一個錯誤。
[[ $A -eq 1 ]]
將起作用。
可能重複[bash:雙或單括號,括號,花括號](http://stackoverflow.com/questions/2188199/bash-double-or-single-bracket-parentheses-curly-braces)和[ \ [和\ [\ [在bash中?](http://stackoverflow.com/q/3427872/218196))之間有什麼區別? –