Comment on page
pkgx & Scripting
$ pkgx ./script.py
pkgx: running python ./script.py
$ pkgx ./script.ts
pkgx: running: deno run ./script.ts
$ head -n1 ./script
$ pkgx ./script
pkgx: running: ruby ./script
We read the shebang and install the interpreter before executing the script. If there is no shebang we use the default interpreter for the file extension.
$ chmod +x ./my-script.py
pkgxis typical for tools that have no POSIX location.
-Sparameter is required to pass multiple arguments.
Scripts are the glue that allows open source to be composed into powerful new tools. With our
+pkgsyntax you make anything in open source available to your script.
#!/usr/bin/env -S pkgx +openssl deno run
eval "$(pkgx --shellcode)"
# ^^ integrates `pkgx` during this script execution
# ^^ requires integration
Robustness requires precisely specifying your environment:
#!/usr/bin/env -S pkgx bash>=4
source <(pkgx --shellcode)
# ^^ bash >=4 is required for this syntax, and eg macOS only comes with bash 3
If you like you can use our cURL-installer in your scripts. If
pkgxis installed then the script just exits and uses that
pkgx, if it’s not installed, it installs pkgx to a temporary directory first.
eval "$(curl -Ssf https://pkgx.sh)"
which pkgx #=> /tmp/pkgx.sh/pkgx
echo $PATH #=> /tmp/pkgx.sh:$PATH
pkgx +node@16 which node #=> /tmp/pkgx.sh/nodejs.org/v16/bin/node
Last modified 1mo ago