Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix $@ vs $* in MATCH and similar functions #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zyga
Copy link
Contributor

@zyga zyga commented Dec 11, 2024

The variables $@ and $* differ subtly in how they are expanded.

  • $* expands to a single value with all the arguments of the program or function joined with spaces, or by the first character of the $IFS variable, to be precise.

    Usually $* is used in messages where the individual arguments and their count is irrelevant.

  • $@ is just like $*, except when in double-quoted string "$@". This form expands to multiple values, properly quoted, so that one set of arguments can be passed safely and correctly into another function.

The aforementioned macros, FATAL, ERROR, MATCH and NOMATCH all used $@ where $* was expected, and thus only really worked with a single value.

The case of MATCH and NOMATCH is more subtle, as usually a single pattern is provided. In general, $* should be used in those cases as $@ does not really do anything different in the error case (the message is the same) but the code is somewhat on the edge of correctness so I chose to adjust them as well.

The variables $@ and $* differ subtly in how they are expanded.

- $* expands to a single value with all the arguments of the program or
  function joined with spaces, or by the first character of the $IFS variable,
  to be precise.

  Usually $* is used in messages where the individual arguments and their count
  is irrelevant.

- $@ is just like $*, _except_ when in double-quoted string "$@". This form
  expands to multiple values, properly quoted, so that one set of arguments can
  be passed safely and correctly into another function.

The aforementioned macros, FATAL, ERROR, MATCH and NOMATCH all used $@ where $* was
expected, and thus only really worked with a single value.

The case of MATCH and NOMATCH is more subtle, as usually a single pattern is
provided. In general, $* should be used in those cases as $@ does not really do
anything different in the error case (the message is the same) but the code is
somewhat on the edge of correctness so I chose to adjust them as well.

Signed-off-by: Zygmunt Krynicki <[email protected]>
@zyga zyga force-pushed the fix/dollar-start-dolar-at branch from 9be753a to e5f269d Compare December 11, 2024 09:53
@zyga zyga changed the title Fix FATAL, ERROR, MATCH and NOMATCH to use Fix $@ vs $* in MATCH and similar functions Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant