Skip to content

Commit

Permalink
add explanation about the shebang
Browse files Browse the repository at this point in the history
  • Loading branch information
hverlin committed Dec 12, 2024
1 parent 8551448 commit eeb1779
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
30 changes: 27 additions & 3 deletions docs/tasks/toml-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,29 @@ outputs = ['target/debug/mycli']

You can use `sources` alone if with [`mise watch`](/cli/watch.html) to run the task when the sources change.

## Shell / Shebang
## shell / shebang

Tasks are executed with `set -e` (`set -o erropt`) if the shell is `sh`, `bash`, or `zsh`. This means that the script
will exit if any command fails. You can disable this by running `set +e` in the script.

You can specify a shell command to run the script with (default is [`sh -c`](/configuration/settings.html#unix_default_inline_shell_args) or [`cmd /c`](/configuration/settings.html#windows_default_inline_shell_args)) or use a shebang:
```toml
[tasks.echo]
run = '''
set +e
cd /nonexistent
echo "This will not fail the task"
'''
```

You can specify a `shell` command to run the script with (default is [`sh -c`](/configuration/settings.html#unix_default_inline_shell_args) or [`cmd /c`](/configuration/settings.html#windows_default_inline_shell_args)):

```toml
[tasks.lint]
shell = 'bash -c'
run = "cargo clippy"
```

or use a shebang:
or use a `shebang`:

```toml
[tasks.lint]
Expand Down Expand Up @@ -288,6 +297,21 @@ puts 'Hello, ruby!'

:::

::: details What's a shebang? What's the difference between `#!/usr/bin/env` and `#!/usr/bin/env -S`

A shebang is the character sequence `#!` at the beginning of a script file that tells the system which program should be used to interpret/execute the script.
The [env command](https://manpages.ubuntu.com/manpages/jammy/man1/env.1.html) comes from GNU Coreutils.

For example, `#!/usr/bin/env python` will run the script with the Python interpreter found in the `PATH`.

The `-S` flag allows passing multiple arguments to the interpreter.
It treats the rest of the line as a single argument string to be split.

This is useful when you need to specify interpreter flags or options.
Example: `#!/usr/bin/env -S python -u` will run Python with unbuffered output

:::

## file

You can specify a file to run as a task:
Expand Down
4 changes: 3 additions & 1 deletion docs/tips-and-tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ console.log(`Running node: ${process.version}`);
This can also be useful in environments where mise isn't activated
(such as a non-interactive session).

You can also download the <https://mise.run> script to use in a project bootstrap script:
## Bootstrap script

You can download the <https://mise.run> script to use in a project bootstrap script:

```sh
curl https://mise.run > setup-mise.sh
Expand Down

0 comments on commit eeb1779

Please sign in to comment.