From 7ea5b4a020b13d278442f9178f8a03208cf0a4b6 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 4 Feb 2025 14:51:38 +0200 Subject: [PATCH] tools: add a small utility script `cmd/tools/vrun`, to make it easier to use .vsh scripts on systems, with `/usr/bin/env` still not supporting `-S` --- cmd/tools/vrun | 26 ++++++++++++++++++++++++++ doc/docs.md | 4 ++++ 2 files changed, 30 insertions(+) create mode 100755 cmd/tools/vrun diff --git a/cmd/tools/vrun b/cmd/tools/vrun new file mode 100755 index 0000000000..4ae9f95d3b --- /dev/null +++ b/cmd/tools/vrun @@ -0,0 +1,26 @@ +#!/bin/sh +v run $@ + +## The purpose of this script, is to make it easier to run V scripts on systems, where +## the `/usr/bin/env` implementation, does not yet support a `-S` option. +## Notes: FreeBSD's env supports it since 2006. +## GNU's coreutils env supports it since 2018. +## However, for example BusyBox's env still does not (2025/02/04), and there may +## be others like it too :-| . + +## On such systems, you can copy this script, or symlink it, somewhere in your PATH, +## and then start your .vsh scripts with: `#!/usr/bin/env vrun`. +## You can also start them with `#!/usr/bin/env /full/path/to/v/cmd/tools/vrun` directly, +## if you prefer. + +## You can check, if it works, by saving this as a /tmp/args.vsh file: +## ```v +## !/usr/bin/env vrun +## println(arguments()) +## ``` +## +## ... then run `chmod 755 /tmp/args.vsh`, and finally run: +## `/tmp/args.vsh abc 123` +## +## If everything works correctly, you should see something like: +## ['/tmp/args', 'abc', '123'] diff --git a/doc/docs.md b/doc/docs.md index 893e0c864c..51c0d21be6 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -8132,6 +8132,10 @@ were made and keep the binary as `tmp.`. **Caution**: if this fi exists the file will be overridden. If you want to rebuild each time and not keep this binary instead use `#!/usr/bin/env -S v -raw-vsh-tmp-prefix tmp run`. +Note: there is a small shell script `cmd/tools/vrun`, that can be useful for systems, that have an +env program (`/usr/bin/env`), that still does not support an `-S` option (like BusyBox). +See https://github.com/vlang/v/blob/master/cmd/tools/vrun for more details. + # Appendices ## Appendix I: Keywords