From ef3629fae333c7b9d1318421ce381543a9a6c51f Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Mon, 3 Jan 2022 19:04:34 +0100 Subject: [PATCH] Mention "$@" in the README (#1064) --- README.adoc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.adoc b/README.adoc index ca97a5b..ff290e4 100644 --- a/README.adoc +++ b/README.adoc @@ -619,6 +619,25 @@ foo hello ``` +When using an `sh`-compatible shell, such as `bash` or `zsh`, `$@` expands to the positional arguments given to the recipe, starting from one. When used within double quotes as `"$@"`, arguments including whitespace will be passed on as if they were double-quoted. That is, "$@" is equivalent to "$1" "$2"... When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are removed). + +This example recipe will print arguments one by one on separate lines: + +```make +set positional-arguments + +@test *args='': + bash -c 'while (( "$#" )); do echo - $1; shift; done' -- "$@" +``` + +Running it with _two_ arguments: + +``` +$ just test foo "bar baz" +- foo +- bar baz +``` + ==== Shell The `shell` setting controls the command used to invoke recipe lines and backticks. Shebang recipes are unaffected.