[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How functions are defined

From: Robert Elz
Subject: Re: How functions are defined
Date: Tue, 28 Apr 2020 22:46:52 +0700

    Date:        Mon, 27 Apr 2020 22:03:47 -0400
    From:        address@hidden (Dale R. Worley)
    Message-ID:  <address@hidden>

  | While I was looking at the details of parsing function definitions, I
  | tripped on something I should have noticed long ago.  In the function
  | definition
  |     function foo() {
  |         command
  |     }

I think this is your problem.   The definition of a function is

        name ( ) compound-command

and in the ksh/bash variant version

        function name ( ) compound-command

There are no braces in the syntax (and I omitted redirections which are
not relevant here).

When looking for a "compound-command" we start out looking for the
first word of a command, and that's exactly where a reserved word
can be found.

Some shells actually permit

        name ( ) command

instead where it is even clearer (but which gives rise to one small,
and mostly irrelevant, ambiguity - also not relevant here.)

Note that the text you quoted:

   Reserved words are words that have a special meaning to the shell.  The
   following words are recognized as reserved when unquoted and either the
   first word of a simple command ...

note that "first word" has nothing to do with lines, that the "name ()"
comes earlier doesn't mean that a command (or compound-command) doesn't
follow, and that thing starts with a "first word" (of itself).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]