1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

docs: add comments from #1115 to faq and styleguide (#1202)

This commit is contained in:
Pete Davison
2023-06-04 01:30:45 +01:00
committed by GitHub
parent 7a2f8d691c
commit 105756eb27
2 changed files with 72 additions and 3 deletions

View File

@@ -7,9 +7,6 @@ sidebar_position: 7
This page contains a list of frequently asked questions about Task.
- [Why won't my task update my shell environment?](#why-wont-my-task-update-my-shell-environment)
- ['x' builtin command doesn't work on Windows](#x-builtin-command-doesnt-work-on-windows)
## Why won't my task update my shell environment?
This is a limitation of how shells work. Task runs as a subprocess of your
@@ -30,6 +27,54 @@ my-shell-env:
Now run `eval $(task my-shell-env)` and the variables `$FOO` and `$BAR` will be
available in your shell.
## I can't reuse my shell in a task's commands
Task runs each command as a separate shell process, so something you do in one
command won't effect any future commands. For example, this won't work:
```yaml
version: '3'
tasks:
foo:
cmds:
- a=foo
- echo $a
# outputs ""
```
To work around this you can either use a multiline command:
```yaml
version: '3'
tasks:
foo:
cmds:
- |
a=foo
echo $a
# outputs "foo"
```
Or for more complex multi-line commands it is recommended to move your code into
a separate file and call that instead:
```yaml
version: '3'
tasks:
foo:
cmds:
- ./foo-printer.bash
```
```bash
#!/bin/bash
a=foo
echo $a
```
## 'x' builtin command doesn't work on Windows
The default shell on Windows (`cmd` and `powershell`) do not have commands like

View File

@@ -214,3 +214,27 @@ tasks:
```
This is also done automatically when using included Taskfiles.
## Prefer external scripts over complex multi-line commands
```yaml
# bad
version: '3'
tasks:
build:
cmds:
- |
for i in $(seq 1 10); do
echo $i
echo "some other complex logic"
done'
# good
version: '3'
tasks:
build:
cmds:
- ./scripts/my_complex_script.sh
```