Skip to content

Commands starting with "!" don’t always work #2355

@christophberger

Description

@christophberger

Description

A Taskfile that worked fine for months is now failing when trying to evaluate an environment variable within a precondition.

This Taskfile works:

version: "3"

env:
  PORT: 1313

tasks:
  port:
    cmds:
      - echo $PORT

Output:

> task port
task: [port] echo $PORT
1313

This one fails:

version: "3"

env:
  PORT: 1313

tasks:
  noserverrunning:
    preconditions:
      - sh: "! nc -z localhost $PORT"
        msg: Port $PORT is not available.
  port:
    deps:
      - noserverrunning
    cmds:
      - echo $PORT

Output:

> task port
task: Port $PORT is not available.
task: precondition not met

Expected (if the precondition isn't met): Port 1313 is not available.

The Taskfile has been the same for months, but when I used it today, it started failing. Hence I assume it's a bug.

Version

3.44.1

Operating system

macOS Sequoia 15.5

Experiments Enabled

No response

Example Taskfile

version: "3"

env:
  PORT: 1313

tasks:
  noserverrunning:
    preconditions:
      - sh: "! nc -z localhost $PORT"
        msg: Port $PORT is not available.
  port:
    deps:
      - noserverrunning
    cmds:
      - echo $PORT

Metadata

Metadata

Assignees

No one assigned

    Labels

    dep: mvdan/shIssues related to the upstream interpreter used by Task.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions