bug-bash
[Top][All Lists]
Advanced

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

Re: bash dislikes empty functions or flow control bodies


From: Robert Elz
Subject: Re: bash dislikes empty functions or flow control bodies
Date: Tue, 18 Jan 2022 22:55:08 +0700

    Date:        Tue, 18 Jan 2022 12:44:46 +0100
    From:        l.bashbug@scarydevilmonastery.net
    Message-ID:  
<1642506286.659529.80113.nullmailer@latitude.scarydevilmonastery.net>

  |    a: defining an empty function will throw a syntax error
  |    b: defining an empty bodies flow control construct will thow a syntax 
error
  |
  | While it may be debatable whether such construct could serve any purpose
  | (they actually can), perceived lack of purpose doesn't qualify them as
  | syntactically wrong. They aren't.

They are, and always have been.   The sh syntax doesn't permit completely
empty statements, and never has.

  | Would they be syntactically wrong,
  | the syntax error would continue to exist after adding a harmless
  | "no operation" equivalent.

That makes no sense at all.   If the question were semantics, that
might be a more reasonable thing to say, but it isn't.   The syntax
requires words to exist, ':' is a word (it is even a command, which
is more than is required).

If you want the more elementary case, even less than this, try

        E=

        fn() { $E; }

(though that one is dangerous, as it is the value of E at the time
the function is called which controls what happens, other than the question
of the syntax, not its value at definition time.

        if true then $E; fi
        while $E; do $E; done

(the latter is an infinite loop, doing nothing, executing nothing, just
the shell using all the available CPU).

kre





reply via email to

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