task icon indicating copy to clipboard operation
task copied to clipboard

Environment variables cannot reference other environment variables

Open bravely-beep opened this issue 8 months ago • 2 comments

Description

After creating this Taskfile.yml:

version: "3"

env: { FOO: foo }

tasks:
  print_foobar: 
    env: { FOOBAR: { sh: echo "$FOO"bar } }
    cmd: echo "$FOOBAR"

and running task print_foobar, I get the output:

task: [print_foobar] echo "$FOOBAR" bar

when I was expecting

task: [print_foobar] echo "$FOOBAR" foobar

Version

3.39.2

Operating system

NixOS

Experiments Enabled

None

Example Taskfile

version: "3"

env: { FOO: foo }

tasks:
  print_foobar: 
    env: { FOOBAR: { sh: echo "$FOO"bar } }
    cmd: echo "$FOOBAR"

bravely-beep avatar May 24 '25 21:05 bravely-beep

Another taskfile example

version: "3"

dotenv:
  - .env

env:
  PORT: {{$PORT | default: 8080}}

tasks:
  echo: 
    cmd: echo $PORT

Expected behavior

If .env contains PORT=9999

task: [echo] echo $PORT
9999

If .env contains nothing

task: [echo] echo $PORT
8080

CodeTroopers avatar Aug 13 '25 14:08 CodeTroopers

@bravely-beep This seems to work as you expect with the latest versions of Task.

@CodeTroopers The condition you observe is very likely a duplicate of the issues resolved by #2288 or #2403.

trulede avatar Nov 05 '25 21:11 trulede