|
2 | 2 | title: Bicep CLI commands |
3 | 3 | description: Learn about the commands that you can use in the Bicep CLI. These commands include building JSON Azure Resource Manager templates from Bicep. |
4 | 4 | ms.topic: reference |
5 | | -ms.date: 03/02/2026 |
| 5 | +ms.date: 04/09/2026 |
6 | 6 | ms.custom: devx-track-azurecli, devx-track-bicep, devx-track-arm-template |
7 | 7 | --- |
8 | 8 |
|
@@ -138,6 +138,192 @@ az bicep build-params --file params.bicepparam |
138 | 138 |
|
139 | 139 | This command converts a _params.bicepparam_ parameters file into a _params.json_ JSON parameters file. |
140 | 140 |
|
| 141 | +## console |
| 142 | + |
| 143 | +The `console` command is available in Bicep CLI v0.42.1 or later. It provides an interactive Read-Eval-Print Loop (REPL) environment for Bicep expressions. It allows you to experiment with Bicep functions and expressions in an interactive console session, especially useful when authoring or testing Bicep logic such as expressions, functions, and user-defined functions.. It supports the following features: |
| 144 | + |
| 145 | +* **Interactive Expression Evaluation**: Enter Bicep expressions and see their evaluated results immediately |
| 146 | +* **Variable Declarations**: Define variables using `var name = expression syntax and reuse them in subsequent expressions |
| 147 | +* **Multi-line Input**: Support for complex multi-line expressions with automatic structural completion detection |
| 148 | +* **Syntax Highlighting**: Real-time syntax highlighting for input and output |
| 149 | + |
| 150 | +The `console` command has these limitations: |
| 151 | + |
| 152 | +* No support for expressions requiring Azure context, e.g. `resourceGroup()` |
| 153 | +* No support for for-loop expressions, e.g. `[for i in range(0, x): i]` |
| 154 | +* No persistent state between console sessions |
| 155 | +* No completions support |
| 156 | + |
| 157 | +Use the following command to start a Bicep console session: |
| 158 | + |
| 159 | +# [Bicep CLI](#tab/bicep-cli) |
| 160 | + |
| 161 | +```powershell |
| 162 | +bicep console |
| 163 | +``` |
| 164 | + |
| 165 | +# [Azure CLI](#tab/azure-cli) |
| 166 | + |
| 167 | +N/A |
| 168 | + |
| 169 | +--- |
| 170 | + |
| 171 | +To exit the console, press `ESC` or use the `exit` command. |
| 172 | + |
| 173 | +### Examples |
| 174 | + |
| 175 | +#### Simple Expressions |
| 176 | + |
| 177 | +```bicep |
| 178 | +> 1 + 2 |
| 179 | +3 |
| 180 | +
|
| 181 | +> 'Hello, ${'World!'}' |
| 182 | +'Hello, World!' |
| 183 | +
|
| 184 | +> length(['a', 'b', 'c']) |
| 185 | +3 |
| 186 | +``` |
| 187 | + |
| 188 | +#### Variable Declarations |
| 189 | + |
| 190 | +```bicep |
| 191 | +> var myName = 'John' |
| 192 | +> var greeting = 'Hello, ${myName}!' |
| 193 | +> greeting |
| 194 | +'Hello, John!' |
| 195 | +``` |
| 196 | + |
| 197 | +#### Multi-line Expressions |
| 198 | + |
| 199 | +The console automatically detects when expressions are structurally complete: |
| 200 | + |
| 201 | +```bicep |
| 202 | +> var config = { |
| 203 | + name: 'myApp' |
| 204 | + version: '1.0.0' |
| 205 | + settings: { |
| 206 | + debug: true |
| 207 | + timeout: 30 |
| 208 | + } |
| 209 | +} |
| 210 | +> config.settings.debug |
| 211 | +true |
| 212 | +``` |
| 213 | + |
| 214 | +#### Complex Expressions |
| 215 | + |
| 216 | +##### Lambdas |
| 217 | + |
| 218 | +```bicep |
| 219 | +> var users = [ |
| 220 | + { name: 'Alice', age: 30 } |
| 221 | + { name: 'Bob', age: 25 } |
| 222 | +] |
| 223 | +> map(users, user => user.name) |
| 224 | +['Alice', 'Bob'] |
| 225 | +
|
| 226 | +> filter(users, user => user.age > 26) |
| 227 | +[ |
| 228 | + { |
| 229 | + age: 30 |
| 230 | + name: 'Alice' |
| 231 | + } |
| 232 | +] |
| 233 | +``` |
| 234 | + |
| 235 | +##### User-defined types and functions |
| 236 | + |
| 237 | +```bicep |
| 238 | +> type PersonType = { |
| 239 | + name: string |
| 240 | + age: int |
| 241 | +} |
| 242 | +> func sayHi(person PersonType) string => 'Hello ${person.name}, you are ${person.age} years old!' |
| 243 | +> var alice = { |
| 244 | + name: 'Alice' |
| 245 | + age: 30 |
| 246 | +} |
| 247 | +> [ sayHi(alice), sayHi({ name: 'Bob', age: 25 })] |
| 248 | +[ |
| 249 | + 'Hello Alice, you are 30 years old!' |
| 250 | + 'Hello Bob, you are 25 years old!' |
| 251 | +] |
| 252 | +``` |
| 253 | + |
| 254 | +#### Loading content from files |
| 255 | + |
| 256 | +Bicep console also supports the [`load*()` functions](./bicep-functions-files.md#file-functions-for-bicep). The directory from which the `bicep console` command is run is used as the _current directory_ when evaluating the `load*()` functions |
| 257 | + |
| 258 | +The following example shows how to use [`loadDirectoryFileInfo()`](./bicep-functions-files.md#loaddirectoryfileinfo) to load information about all Bicep files in a directory: |
| 259 | + |
| 260 | +```bicep |
| 261 | +> loadDirectoryFileInfo('./modules/', '*.bicep') |
| 262 | +[ |
| 263 | + { |
| 264 | + relativePath: 'C:/Bicep/modules/appService.bicep' |
| 265 | + baseName: 'appService.bicep' |
| 266 | + extension: '.bicep' |
| 267 | + } |
| 268 | +] |
| 269 | +``` |
| 270 | + |
| 271 | +#### Piping and standard input/output redirection |
| 272 | + |
| 273 | +The console command supports evaluating expressions provided through piping or redirected standard input, enabling scenarios like: |
| 274 | + |
| 275 | +* Passing expression text via echo |
| 276 | +* Composing scripts that feed expressions into the console |
| 277 | +* Rapid testing of generated or transformed Bicep snippets |
| 278 | + |
| 279 | +**Powershell**: |
| 280 | + |
| 281 | +```powershell |
| 282 | +# piped input |
| 283 | +"parseCidr('10.144.0.0/20')" | bicep console |
| 284 | +``` |
| 285 | + |
| 286 | +**Bash**: |
| 287 | + |
| 288 | +```bash |
| 289 | +# piped input |
| 290 | +echo "parseCidr('10.144.0.0/20')" | bicep console |
| 291 | +# stdin redirection from file content |
| 292 | +bicep console < test.txt |
| 293 | +``` |
| 294 | + |
| 295 | +Multi-line input is also supported: |
| 296 | + |
| 297 | +```powershell |
| 298 | +"{ |
| 299 | +> foo: 'bar' |
| 300 | +> }.foo" | bicep console |
| 301 | +``` |
| 302 | + |
| 303 | +The output is `'bar'`. |
| 304 | + |
| 305 | +Output redirection is also supported: |
| 306 | + |
| 307 | +```bash |
| 308 | +"toObject([{name:'Evie', age:4},{name:'Casper', age:3}], x => x.name)" | bicep console > output.json |
| 309 | +more output.json |
| 310 | +``` |
| 311 | + |
| 312 | +The output is : |
| 313 | + |
| 314 | +```json |
| 315 | +{ |
| 316 | + Evie: { |
| 317 | + name: 'Evie' |
| 318 | + age: 4 |
| 319 | + } |
| 320 | + Casper: { |
| 321 | + name: 'Casper' |
| 322 | + age: 3 |
| 323 | + } |
| 324 | +} |
| 325 | +``` |
| 326 | + |
141 | 327 | ## decompile |
142 | 328 |
|
143 | 329 | The `decompile` command converts a JSON ARM template to a Bicep file: |
|
0 commit comments