Skip to content

add "call" command

Heinrich Schuchardt u-boot 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest0 of 3 patches 0 repliesNew

Patches in v1 No applies recorded yet

None of the 3 patches the cover letter announces are in this archive.

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] add "call" command
Quoted 16 lines · Rasmus Villemoes

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

Quoted 6 lines

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

Quoted 17 lines

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