Scripts & Runtime Examples
Examples for shell scripts, Python scripts, working directories, shell selection, and reproducible runtimes.
Shell Scripts
yaml
steps:
- run: |
#!/bin/bash
cd /tmp
echo "hello world" > hello
cat hello
ls -laRun shell script with default shell.
Shebang Script
yaml
tools:
- astral-sh/uv@0.11.14
steps:
- run: |
#!/usr/bin/env -S uv run --python 3.13.9 python
import platform
print(platform.python_version())Runs with the interpreter declared in the shebang.
Python Scripts
yaml
tools:
- astral-sh/uv@0.11.14
steps:
- run: |
import os
import datetime
print(f"Current directory: {os.getcwd()}")
print(f"Current time: {datetime.datetime.now()}")
with:
shell: uv run --python 3.13.9 pythonExecute script with specific interpreter.
Multi-Step Scripts
yaml
steps:
- run: |
#!/bin/bash
set -e
echo "Starting process..."
echo "Preparing environment"
echo "Running main task..."
echo "Running main process"
echo "Cleaning up..."
echo "Cleaning up"Working Directory
yaml
working_dir: /tmp
steps:
- id: show_default_dir
run: pwd # Outputs: /tmp
- id: create_data_dir
run: mkdir -p data
depends: show_default_dir
- id: show_data_dir
working_dir: /tmp/data
run: pwd # Outputs: /tmp/data
depends: create_data_dirShell Selection
yaml
shell: /bin/bash # Default shell for all steps
shell_args: ["-e"] # Default shell args for all steps
steps:
- run: echo hello world | xargs echo
- run: echo "from zsh" # Override for a single step
with:
shell: /bin/zshReproducible Env with Nix Shell
Note: Requires nix-shell to be installed separately. Not included in Dagu binary or container.
yaml
steps:
- run: |
python3 --version
curl --version
jq --version
with:
shell: nix-shell
shell_packages: [python3, curl, jq]