Reptorian G'MIC Filters

FYI, $# in a command gives the number of specified arguments, so basically $# = narg($*) .
I’m not sure there is any interest in using narg($*) then.

I’m not sure about what you expect here, but let me develop a bit on command instanciation:
When a G’MIC command is invoked in a script, the interpreter does the following things in this order:

  1. Command instanciation: the interpreter generates a new instance of the command, where all the arguments $1,.. are replaced by their provided values. So, basically, for each command call with different arguments, the interpreter internally generates a different version of the command to be executed.
  2. Command execution: the interpreter begins the interpretation of the instanced command.

So, you really have to view the command argument-related strings ${3=something} as something very different from variables. Their substitution is not done at the same time
(argument values are substituted during command instanciation, while variable values are substituted during command execution).
This particularly means that a string like ${3=something} in a command can be put anywhere, the argument $3 will always be substituted by something if it is not specified by the command caller. You cannot decide to put its default value only in a portion of code. (what could be its value anywhere else, if the argument is not specified ?).

If you want to deal with conditional values for arguments, just use variables instead. You are sure they will be substituted during command execution. Something like:

foo: skip ${3=}
  if narg($3) arg3=$3 else arg3=foo fi
  echo "ARG3  = "$arg3
1 Like