Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of reading script from stdin using echo #6567

Merged
merged 2 commits into from
Aug 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/guides/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ print("hello world!")
EOF
```

or

```bash
echo '
print("hello world!")
' | uv run -
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just show this as a one-line, e.g. $ echo 'print("hello world!")' | uv run - with "console" instead of "bash" syntax? I'd even show this first, then say something like... "Or, if your shell supports heredocs:"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds fine to me. My first thought had been to write it as a one-liner, but then I figured that the reason for the way the existing example was written was that most scripts users might want to run would have multiple lines, so the example should make it easy to add more lines to the script. But your suggestion is cleaner, and users can easily convert the one-liner to a multi-liner, so I'll make the change you suggested.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks!

```

Note that if you use `uv run` in a _project_, i.e. a directory with a `pyproject.toml`, it will
install the current project before running the script. If your script does not depend on the
project, use the `--no-project` flag to skip this:
Expand Down
Loading