Skip to content

Commit 1d7dae1

Browse files
committed
document bicep console
1 parent c16ed08 commit 1d7dae1

1 file changed

Lines changed: 196 additions & 1 deletion

File tree

articles/azure-resource-manager/bicep/bicep-cli.md

Lines changed: 196 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Bicep CLI commands
33
description: Learn about the commands that you can use in the Bicep CLI. These commands include building JSON Azure Resource Manager templates from Bicep.
44
ms.topic: reference
5-
ms.date: 03/02/2026
5+
ms.date: 04/09/2026
66
ms.custom: devx-track-azurecli, devx-track-bicep, devx-track-arm-template
77
---
88

@@ -138,6 +138,201 @@ az bicep build-params --file params.bicepparam
138138

139139
This command converts a _params.bicepparam_ parameters file into a _params.json_ JSON parameters file.
140140

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. 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+
```bicep
177+
> 1 + 2
178+
3
179+
180+
> 'Hello, ' + 'World!'
181+
'Hello, World!'
182+
183+
> length(['a', 'b', 'c'])
184+
3
185+
186+
```
187+
188+
#### Simple Expressions
189+
190+
```bicep
191+
> 1 + 2
192+
3
193+
194+
> 'Hello, ${'World!'}'
195+
'Hello, World!'
196+
197+
> length(['a', 'b', 'c'])
198+
3
199+
```
200+
201+
#### Variable Declarations
202+
203+
```bicep
204+
> var myName = 'John'
205+
> var greeting = 'Hello, ${myName}!'
206+
> greeting
207+
'Hello, John!'
208+
```
209+
210+
#### Multi-line Expressions
211+
212+
The console automatically detects when expressions are structurally complete:
213+
214+
```bicep
215+
> var config = {
216+
name: 'myApp'
217+
version: '1.0.0'
218+
settings: {
219+
debug: true
220+
timeout: 30
221+
}
222+
}
223+
> config.settings.debug
224+
true
225+
```
226+
227+
#### Complex Expressions
228+
229+
##### Lambdas
230+
231+
```bicep
232+
> var users = [
233+
{ name: 'Alice', age: 30 }
234+
{ name: 'Bob', age: 25 }
235+
]
236+
> map(users, user => user.name)
237+
['Alice', 'Bob']
238+
239+
> filter(users, user => user.age > 26)
240+
[
241+
{
242+
age: 30
243+
name: 'Alice'
244+
}
245+
]
246+
```
247+
248+
##### User-defined types and functions
249+
250+
```bicep
251+
> type PersonType = {
252+
name: string
253+
age: int
254+
}
255+
> func sayHi(person PersonType) string => 'Hello ${person.name}, you are ${person.age} years old!'
256+
> var alice = {
257+
name: 'Alice'
258+
age: 30
259+
}
260+
> [ sayHi(alice), sayHi({ name: 'Bob', age: 25 })]
261+
[
262+
'Hello Alice, you are 30 years old!'
263+
'Hello Bob, you are 25 years old!'
264+
]
265+
```
266+
267+
#### Loading content from files
268+
269+
Bicep console also supports the [`load*()` functions](./bicep-functions-files.md#file-functions-for-bicep). Note: The directory from which the `bicep console` command is run is used as the _current directory_ when evaluating the `load*()` functions
270+
271+
The following example shows how to use `loadDirectoryFileInfo()` to load information about all Bicep files in a directory:
272+
273+
```bicep
274+
> loadDirectoryFileInfo('./modules/', '*.bicep')
275+
[
276+
{
277+
relativePath: 'C:/Bicep/modules/appService.bicep'
278+
baseName: 'appService.bicep'
279+
extension: '.bicep'
280+
}
281+
]
282+
```
283+
284+
#### Piping and standard input/output redirection
285+
286+
The console command supports evaluating expressions provided through piping or redirected standard input, i.e.:
287+
288+
**Powershell**:
289+
290+
```powershell
291+
# piped input
292+
"parseCidr('10.144.0.0/20')" | bicep console
293+
```
294+
295+
**Bash**:
296+
297+
```bash
298+
# piped input
299+
echo "parseCidr('10.144.0.0/20')" | bicep console
300+
# stdin redirection from file content
301+
bicep console < test.txt
302+
```
303+
304+
Multi-line input is also supported, i.e:
305+
306+
```powershell
307+
"{
308+
> foo: 'bar'
309+
> }.foo" | bicep console
310+
```
311+
312+
The output is `'bar'`.
313+
314+
Output redirection is also supported:
315+
316+
```bash
317+
"toObject([{name:'Evie', age:4},{name:'Casper', age:3}], x => x.name)" | bicep console > output.json
318+
more output.json
319+
```
320+
321+
The output is :
322+
323+
```json
324+
{
325+
Evie: {
326+
name: 'Evie'
327+
age: 4
328+
}
329+
Casper: {
330+
name: 'Casper'
331+
age: 3
332+
}
333+
}
334+
```
335+
141336
## decompile
142337

143338
The `decompile` command converts a JSON ARM template to a Bicep file:

0 commit comments

Comments
 (0)