[docs] Add shebang section for scripts (#11553)

<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

Documentation only. Adds a section in scripts.md about running uv
scripts with a shebang line

## Test Plan

n/a

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
Samay Kapadia 2025-04-16 17:20:27 +02:00 committed by GitHub
parent e58cc39238
commit d9243cee7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -217,6 +217,39 @@ print(Point)
is not installed — see the documentation on [Python versions](../concepts/python-versions.md) for
more details.
## Using a shebang to create an executable file
A shebang can be added to make a script executable without using `uv run` — this makes it easy to
run scripts that are on your `PATH` or in the current folder.
For example, create a file called `greet` with the following contents
```python title="greet"
#!/usr/bin/env -S uv run --script
print("Hello, world!")
```
Ensure that your script is executable, e.g., with `chmod +x greet`, then run the script:
```console
$ ./greet
Hello, world!
```
Declaration of dependencies is also supported in this context, for example:
```python title="example"
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# dependencies = ["httpx"]
# ///
import httpx
print(httpx.get("https://example.com"))
```
## Using alternative package indexes
If you wish to use an alternative [package index](../configuration/indexes.md) to resolve