task: Cannot correctly modify environment variable PATH for use in task commands
- Task version: 2.5.1
- OS: Windows 10 Professional (64-bit)
- Example Taskfile showing the issue:
# https://taskfile.dev
version: '2'
tasks:
a:
cmds:
- echo "Task a"
- echo $PATH
b:
cmds:
- echo "Task b"
- echo "{{.PATH}}"
c:
env:
PATH: tools
cmds:
- echo "Task c"
- echo $PATH
d:
env:
PATH: tools
cmds:
- echo "Task d"
- echo "{{.PATH}}"
e:
env:
PATH:
sh: echo "tools;$PATH"
cmds:
- echo "Task e"
- echo $PATH
f:
env:
PATH:
sh: echo "./tools;$PATH"
cmds:
- echo "Task f"
- echo $PATH
g:
env:
PATH:
sh: echo "$(realpath ./tools);$PATH"
cmds:
- echo "Task g"
- echo $PATH
Hello. Firstly, thank-you for Task. It has, overall, made my development life easier and more pleasant.
I don’t know if the problem I have is a bug or if I simply don’t understand the correct way to achieve my goal. I’d like to be able to modify the environment variable PATH (either prepending or appending a project-specific directory to the existing value), but I can’t figure out how to do this using the set of commands available within Taskfiles.
To provide context, my Taskfile is for use in building go applications. Some applications (projects) require project-specific build tools/helpers that I place in a top-level tools subdirectory (i.e., <project name>/tools). Note that my Taskfile resides at <project name>/Taskfile.yml. I wish to use the go generate command, which effectively requires that external generation tools be accessible via PATH, so I must add <project name>/tools to PATH before running go generate in the task.
While I’m working in Windows, I’m making effective use of busybox-w32 to provide a fairly comprehensive set of what are otherwise Linux tools, so things like cp, echo and realpath are available. I’ve also tried this via WSL such that things are more like a real Linux environment, with the same results.
The output I get from the above Taskfile (when run under sh or bash via WSL) is as follows (results in native Windows are the same):
$ task a; task b; task c; task d; task e; task f; task g
echo "Task a"
Task a
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
echo "Task b"
Task b
echo "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
echo "Task c"
Task c
echo $PATH
tools
echo "Task d"
Task d
echo "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
echo "Task e"
Task e
echo $PATH
tools;/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
echo "Task f"
Task f
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
echo "Task g"
Task g
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
Tasks a, b, c and d are just simple tests; it’s tasks e, f and g that illustrate the real issue. Task e works correctly, prepending tools to the current PATH, but neither f nor g have any effect. Task g is the closest to what I need in terms of operations (i.e., adding the absolute path of a project-specific directory).
I’d greatly appreciate any input you could provide on this issue. Thanks in advance.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17 (9 by maintainers)
Came here via Google, so for reference: Same here, running Linux (Fedora 37 wit
go-taskinstalled via DNF - reported version is “unknown”, but RPM says3.20.0). Installingv3.21.0from releases worked though.Or not 😕 might have myt test cases mixed up, sorry…
Probably b/c https://github.com/go-task/task/issues/482
@i-am-david-fernandez Sorry, I’ll take long to debug this since my available time has being low recently, and I don’t use Windows often nowadays. I do plan to debug and fix this, though.
Just a friendly reminder that @mvdan has no interest in Task, and likely won’t digest a long thread like this to understand the problem. If we think we found a problem on mvdan/sh we should try to reproducing it in a small Go script (importing the
sh’s packages directly) and open a more specific issue there.I should note that I’ve been providing output produced via
WSLunder the assumption that its closeness to Linux makes it more useful from a debugging perspective. My working environment isPowershellin nativeWindowsand that’s where I’m most interested in having this work.I apologise if the
WSLstuff has become a distraction.Here’s the output from
Powershellof the firstTaskfileI posted (the opening post in this thread):I clearly missed that
task gpartially works: thePATHas displayed has stuff prepended, but, whether because slashes are wrong or semi-colons have been swapped with colons, the end result isn’t correct (I tried running something from that prepended path via the task and it fails as it can’t find it inPATH).For ease of reference, here is
task g:Changing the method of specifying the
PATHfromecho "$(realpath ./tools);$PATH"tosh: echo "$(pwd)\tools;$PATH"resolves the slash issue:But, perhaps because of the colons, still doesn’t ultimately work.