shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

Weird behaviour when bash function has the Unicode name

Open giappi opened this issue 4 years ago • 1 comments

For bugs

  • Rule Id (if any, e.g. SC1000): SC1036, SC1088
  • My shellcheck version (shellcheck --version or 'online'): online
  • [x] I tried on shellcheck.net and verified that this is still a problem on the latest commit
  • [ ] It's not reproducible on shellcheck.net, but I think that's because it's an OS, configuration or encoding issue

For new checks and feature suggestions

  • [x] shellcheck.net (i.e. the latest commit) currently gives no useful warnings about this
  • [ ] I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related

Here's a snippet or screenshot that shows the problem:

#!/bin/bash

function ■()
{
    echo "■ $@"
}

Here's what shellcheck currently says:

Line 3	SC1036: '(' is invalid here. Did you forget to escape it?
Line 3	SC1088: Parsing stopped here. Invalid use of parentheses?

Here's what I wanted or expected to see:

Unicode is valid bash function name. In case of it does not support Unicode, I think it should show the error message like "invalid function name".

giappi avatar Dec 30 '21 14:12 giappi

I'm not too surprised shellcheck does not accept that. It should though, as in the bash man page, one can read:

In default mode, a function name can be any unquoted shell word that does not contain $

I could not quite find what a shell word is, as the definition is a bit vague:

A sequence of characters considered as a single unit by the shell.

I suspect this means pretty much any sequence of unicode characters.

This is confirmed if you try very weird function names:

[]{}#()  { echo "ok"; }

This actually defines a function []{}#, amazingly enough.

Needless to say, shellcheck refuses to parse that.

grondilu avatar Nov 12 '23 09:11 grondilu