[PATCH 0/3] add "call" command

Heinrich Schuchardt
2020-09-25T11:52:17Z

On 25.09.20 13:19, Rasmus Villemoes wrote:
> This adds a way to call a "function" defined in the environment with
> arguments. I.e., whereas
>
> run foo
>
> requires one to set the (shell or environment) variables referenced
> from foo beforehand, with this one can instead do
>
> call foo arg1 arg2 arg3
>
> and use $1... up to $9 in the definition of foo. $# is set so foo can
> make decisions based on that, and ${3:-default} works as expected.
>
> As I write in patch 2, it should be possible to get rid of the "call"
> and simply allow
>
> foo arg1 arg2 arg3
>
> i.e. if the search for a command named foo fails, try an environment
> variable by that name and do it as "call". But that change of
> behaviour, I think, requires a separate opt-in config knob, and can be
> done later if someone actually wants that.

If the behavior is configurable, this will result in users complaining
that a script which they copied does not run on another machine. Please,
do not introduce any configurability here.

Further we cannot first introduce a command call and then eliminate it
due to backward compatibility. We should decide on the final version
beforehand.

In the Linux world you can override a command using an alias. So I am
not sure if a built in command should take precedence over a variable of
the same name or the other way round.

Consider that we already have two types of variables in the shell. Those
that are in the environment and those that are not. Here the environment
variables take precedence.

Try

setenv a;a=4;echo $a;setenv a 5;echo $a;setenv a;echo $a

Best regards

Heinrich

>
> Rasmus Villemoes (3):
> cli_hush.c: refactor handle_dollar() to prepare for cmd_call
> cli_hush.c: add "call" command
> ut: add small hush tests
>
> cmd/Kconfig | 8 ++++
> common/cli_hush.c | 93 +++++++++++++++++++++++++++++++++----
> configs/sandbox64_defconfig | 1 +
> configs/sandbox_defconfig | 1 +
> include/test/suites.h | 1 +
> test/cmd/Makefile | 1 +
> test/cmd/hush.c | 90 +++++++++++++++++++++++++++++++++++
> test/cmd_ut.c | 6 +++
> 8 files changed, 191 insertions(+), 10 deletions(-)
> create mode 100644 test/cmd/hush.c
>