What are the rules for valid identifiers (e.g. functions, vars, etc) in Bash?

后端 未结 5 613
终归单人心
终归单人心 2020-12-03 17:02

What are the syntax rules for identifiers, especially function and variable names, in Bash?

I wrote a Bash script and tested it on various versions of Bash on Ubuntu

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 17:23

    From 3.3 Shell Functions:

    Shell functions are a way to group commands for later execution using a single name for the group. They are executed just like a "regular" command. When the name of a shell function is used as a simple command name, the list of commands associated with that function name is executed. Shell functions are executed in the current shell context; no new process is created to interpret them.

    Functions are declared using this syntax:

    name () compound-command [ redirections ]
    

    or

    function name [()] compound-command [ redirections ]
    

    and from 2 Definitions:

    name

    A word consisting solely of letters, numbers, and underscores, and beginning with a letter or underscore. Names are used as shell variable and function names. Also referred to as an identifier.

提交回复
热议问题