Share via


Bicep 的 Logical 函數

Bicep 提供將值轉換為布林值的 bool 函數。

Azure Resource Manager 範本中的大部分邏輯函數都會由 Bicep 中的邏輯運算子取代。

bool

bool(arg1)

將參數轉換為布林值。

命名空間:sys (部分機器翻譯)。

參數

參數 必要 類型​ 描述
arg1 Yes 字串或整數 要轉換為布林值的值。 字串值 "ture" 的任何大小寫字元組合 (如 "True"、"TRUE"、"tRue", "true") 均視為相等值,且布林值表現為 true,否則為 false。 整數值 0 視為 false,其他所有整數則視為 true

傳回值

轉換值的布林值。

範例

下列範例顯示如何搭配使用 bool 與字串或整數。

output trueString1 bool = bool('true')
output trueString2 bool = bool('trUe')
output falseString1 bool = bool('false')
output falseString2 bool = bool('falSe')
output trueInt2 bool = bool(2)
output trueInt1 bool = bool(1)
output trueIntNeg1 bool = bool(-1)
output falseInt0 bool = bool(0)

上述範例中具有預設值的輸出如下:

名稱 類型
trueString1 Bool true
trueString2 Bool true
falseString1 Bool false
falseString2 Bool false
trueInt2 Bool true
trueInt1 Bool true
trueIntNeg1 Bool true
falseInt Bool false

下一步