Skip to content

Function names containing # not parsed correctly #287

Description

@GB609

Hello and thank you for this plugin.

I've got an issue with bash function declarations not working correctly when not in POSIX mode.
I'm using a function name pattern which includes '#', for example:

function prefix#doSomething {
  echo not working
}

This does not parse. It leads to a syntax error as bash-editor seems to ignore anything following '#' unconditionally. Moreover, the function will not appear in the outline.

According to the docs Section 3.3 - Shell functions:

This defines a shell function named fname. [...]
When the shell is in POSIX mode (see Bash and POSIX), fname must be a valid shell name and may not be the same as one of the special builtins (see Special Builtins). When not in POSIX mode, a function name can be any unquoted shell word that does not contain ‘$’.

When going by the docs, bash should support basically anything other then $ as part of a function name. Now there's the issue that '#' is normally also used to comment. I just tested this. It appears that bash only recognizes # for inline comments when preceeded by a whitespace.

These are code snippets i actually pasted into a bash 5.3.3 command line to test.

# this works a
function a#valid { echo; }

# this does not parse
function #something { echo; }

# syntax errors also
function with_inline_suffix {#
  echo "not parsing"
}

function working_suffix_comment { # something
  echo "this works"
}

This behaviour is documented: 3.1.3 Comments:

[...] a word beginning with ‘#’ introduces a comment. A word begins at the beginning of a line, after unquoted whitespace, or after an operator [...]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions