Skip to content

Shell ​

run: executes a command or a script in a shell on the machine that runs the step. It is the default step type: a step with run: and no action: is a shell step.

Use action: exec when arguments must reach the program exactly as written, with no shell parsing. Use Docker to run the command in a container.

Basic Usage ​

yaml
steps:
  - id: hello
    run: echo "Hello from $(hostname)"

The shell receives the line as one command, so pipes, redirects, $VAR, and $(...) work as in a terminal. The step fails when the shell exits with a non-zero code. Stdout and stderr appear in the step log of the run.

Run Several Commands ​

A list runs its entries one after another. Each entry starts a new shell, and the step stops at the first entry that fails.

yaml
working_dir: .

steps:
  - id: checks
    run:
      - ./scripts/lint.sh
      - ./scripts/test.sh

Entries do not share shell state: a cd, export, or variable in one entry is gone in the next. Use a script when lines depend on each other.

Run a Script ​

A multi-line run: runs as one script, so cd, variables, functions, and control flow carry across lines.

yaml
working_dir: .

steps:
  - id: build
    run: |
      cd app
      npm ci
      npm run build

When the first character of the script starts a shebang and the step does not set with.shell, the shebang interpreter runs the script:

yaml
steps:
  - id: report
    run: |
      #!/usr/bin/env python3
      import platform
      print("python", platform.python_version())

with.shell names the interpreter directly, and it wins over a shebang:

yaml
steps:
  - id: report
    run: |
      import sys
      print(sys.version)
    with:
      shell: python3

Dagu writes the script to a temporary file and deletes it when the step ends. Do not depend on the script's path, name, or $0; use working_dir or DAG_RUN_WORK_DIR when you need a stable location.

Choose a Shell ​

Set shell at the DAG level for every step, and with.shell on a step to override it:

yaml
working_dir: .
shell: ["/bin/bash", "-e", "-u"]

steps:
  - id: build
    run: make build

  - id: notes
    run: Write-Output "release notes"
    with:
      shell: pwsh

Dagu picks the first shell that is set:

  1. Step with.shell (with with.shell_args).
  2. DAG shell (with DAG shell_args).
  3. Server setting default_shell or the DAGU_DEFAULT_SHELL environment variable.
  4. Platform default: $SHELL, then sh on macOS and Linux; pwsh, then powershell, then cmd on Windows.

A shell value is a string split on spaces ("bash -e") or an array (["bash", "-e"]). Use the array form when an argument contains spaces. Shell values can use references such as ${params.shell} or ${env.SHELL_BIN}, resolved when the step starts.

Dagu adds fail-fast flags for some shell families, such as -e for bash and sh. See macOS and Linux and Windows for the rules of each shell.

Run a Program Without a Shell ​

action: exec starts the program directly. Each args item reaches it as one argument, so spaces, quotes, *, and | are passed through as data.

yaml
steps:
  - id: convert
    action: exec
    with:
      command: ffmpeg
      args:
        - -i
        - "input file.mov"
        - -vf
        - scale=1280:-1
        - output.mp4

A command without a path separator is looked up in PATH. Use exec when an argument comes from a parameter or another step and must not be interpreted by a shell.

Pass Values Into Commands ​

Dagu resolves its own references, such as ${params.name}, ${env.NAME}, and ${steps.build.outputs.version}, before the shell starts. Plain $NAME, ${NAME}, $(...), and backticks are left for the shell.

yaml
working_dir: .

params:
  - region: eu-west-1

steps:
  - id: deploy
    run: ./deploy.sh --region "${params.region}" --user "$USER"

Dagu does not shell-escape resolved values. Quote them for the shell, or pass untrusted text through env or action: exec. See Quoting and Escaping.

Read Standard Input ​

stdin names a file whose contents the command reads on standard input. A relative path resolves against the step working directory.

yaml
steps:
  - id: fetch
    run: curl -fsS https://example.com/report.csv

  - id: count
    depends: fetch
    stdin: ${fetch.stdout}
    run: wc -l

${fetch.stdout} is the path of the file that holds the fetch step's stdout. See Standard Input.

Configuration ​

with fields for a run: step. A run: step accepts no other with fields.

FieldRequiredDefaultDescription
shellNoDAG shell, then the server defaultShell or interpreter for this step. String or array. Disables shebang detection and the automatic -e.
shell_argsNoNoneExtra arguments for shell, as an array.
shell_packagesNoNonePackages to provide. Only nix-shell accepts them; see nix-shell.

with fields for action: exec:

FieldRequiredDefaultDescription
commandYesExecutable path, or a name looked up in PATH.
argsNoNoneArguments, one per item. Strings, numbers, and booleans.

DAG-level fields:

FieldDescription
shellDefault shell for every run: step. String or array.
shell_argsArguments appended to the DAG shell.

Other step fields that shell steps use often: working_dir, env, stdin, stdout, stderr, timeout_sec, and retry_policy. See the YAML Specification.

Output ​

  • Stdout and stderr go to the step log. Set stdout.artifact to also save stdout as a run artifact; see Artifacts.
  • Outputs: declare names in outputs and write name=value lines to $DAGU_OUTPUT_FILE. Later steps read them as ${steps.<id>.outputs.<name>}. See Outputs.
  • Exit code: zero succeeds; any other code fails the step. For a list, the first failing entry decides.

Errors and Limits ​

  • A one-line run: or a list entry must not contain a line break after references are resolved. Use a multi-line script instead.
  • Background work started with & is not part of the step result. Call wait in the command when the step must include it.
  • Shell arguments must not carry the command text. Dagu adds the command flag (-c, -Command, /c) itself; the platform pages list the exact rules.
  • shell_packages fails with any shell other than nix-shell.
  • direct is not a valid shell for run:. Use action: exec.

Platform Details ​

  • macOS and Linux: POSIX shells, automatic -e, nix-shell, PATH under launchd and systemd.
  • Windows: PowerShell, cmd.exe, script encoding.

Dagu is open source under the GNU General Public License v3.0.