Skip to main content

Shell Variable

The shell variable type executes a shell command and captures its stdout output.

Basic Usage​

- trigger: ":ip"
replace: "IP: {{ip}}"
vars:
- name: ip
type: shell
params:
cmd: "hostname -I | awk '{print $1}'"

Practical Examples​

System Information​

- trigger: ":disk"
replace: "Disk: {{disk}}"
vars:
- name: disk
type: shell
params:
cmd: "df -h / | tail -1 | awk '{print $3\"/\"$2\" (\"$5\")\"}'"

Uptime​

- trigger: ":uptime"
replace: "Uptime: {{up}}"
vars:
- name: up
type: shell
params:
cmd: "uptime -p | sed 's/up //'"

File Listings​

- trigger: ":files"
replace: "Files:\n{{files}}"
vars:
- name: files
type: shell
params:
cmd: "ls -la | head -10"

Weather (requires curl)​

- trigger: ":weather"
replace: "{{weather}}"
vars:
- name: weather
type: shell
params:
cmd: "curl -s 'wttr.in?format=%C+%t'"

Dynamic Form Values​

Shell variables can populate choice/list options dynamically:

- trigger: ":run"
replace: "Running: {{form.script}}"
vars:
- name: scripts
type: shell
params:
cmd: "ls ~/scripts/*.sh | xargs -n1 basename"
- name: form
type: form
params:
layout: "Select script: [[script]]"
fields:
script:
type: list
values: "{{scripts}}"

Advanced Options​

The shell variable supports additional parameters for more control:

Trimming Output​

By default, trailing whitespace and newlines are trimmed. Disable with trim: false:

- trigger: ":output"
replace: "{{result}}"
vars:
- name: result
type: shell
params:
cmd: "echo ' hello world '"
trim: false

Debug Mode​

Enable debug logging for shell commands to see exact arguments, exit codes, and errors:

- trigger: ":test"
replace: "{{result}}"
vars:
- name: result
type: shell
params:
cmd: "some-command --flag"
debug: true

View debug output with RUST_LOG=debug ce expand ":test".

Shell Selection​

Specify which shell to use with the shell parameter:

- trigger: ":check"
replace: "{{result}}"
vars:
- name: result
type: shell
params:
cmd: "Invoke-Expression 'Get-Date'"
shell: powershell

Supported shells:

  • Linux/macOS: sh, bash, pwsh, nu
  • Windows: cmd, powershell, pwsh, wsl, nu

Useful Environment Variables​

When a shell command runs, these environment variables are available:

  • CE_CONFIG_DIR — Path to the config directory
  • All match variable values (including form field values)

Security Notes​

warning

Shell commands run with the privileges of the current user. Be careful with:

  • Commands that modify files or system state
  • Commands that include user-provided input
  • Commands in shared match files from untrusted sources

See the Security section for guidelines.

What's Next​

Learn about Global Variables for sharing values across matches. Learn about Variable Chaining to combine multiple variables.