Skip to content

Variables declared under vars are exported into the environment of sh: (dynamic variable) #2993

Description

@eitsupi

Description

Variables declared under vars are exported into the environment of sh: (dynamic variable) commands, but not into cmds, status or preconditions.
The behaviour is undocumented.

vars and env are documented as separate concepts, so I expected MY_VAR not to be in the environment at all.
Or, if it is exported, to be exported consistently in both places.

Version

3.53.1

Operating system

Linux

Experiments Enabled

No response

Example Taskfile

version: '3'

vars:
  MY_VAR: leaked

tasks:
  default:
    silent: true
    vars:
      FROM_SH:
        sh: 'echo "MY_VAR=$MY_VAR"'
    cmds:
      - 'echo "dynamic var (sh:) sees {{.FROM_SH}}"'
      - 'echo "cmds sees          MY_VAR=$MY_VAR"'

Activity

  1. trulede commented on Aug 20, 2026

    @trulede
    Contributor

    @eitsupi yes, this is how it works. Yes, it should probably work differently, but it works this way ... so this is how to deal with it. Choose the strategy that works best for you.

    version: '3'
    
    vars:
      MY_VAR: leaked
    
    tasks:
      default:
        silent: true
        vars:
          FROM_SH:
            sh: 'echo "MY_VAR=$MY_VAR"'
        env:
          MY_VAR: '{{.MY_VAR}}'
        cmds:
          - 'echo "dynamic var (sh:) sees {{.FROM_SH}}"'
          - 'echo "cmds sees          MY_VAR=$MY_VAR"'
          - 'echo " MY_VAR={{.MY_VAR}}"'
    

    gives

    $ task
    dynamic var (sh:) sees MY_VAR=leaked
    cmds sees          MY_VAR=leaked
     MY_VAR=leaked
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions