2

This question is loosely related to one of my previous ones. TL;DR from muru's answer is that characters in function name have to be on Portable Character Set in order to be valid for a function name. Problem is that space is on the list (the <space> or <U0020> character), which is why I'm confused as to why I can't do this:

$ $'  '(){ echo "Hullo";}
bash: `'  '': not a valid identifier
$ hello$' 'world(){ echo "hi";}
bash: `hello' 'world': not a valid identifier

With other shells:

$ mksh -c  '\ (){ echo "Hello";} '                                                                                   
mksh:  : invalid function name

$ ksh -c  '\ (){ echo "Hello";} '                                                                                    
ksh:  : invalid function name

$ dash -c  '\ (){ echo "Hello";} '                                                                                   
dash: 1: Syntax error: Bad function name
Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • As mksh -c '1(){ …;}' from your other question worked, did you try this with mksh too? – dessert Dec 17 '17 at 08:21
  • 1
    @dessert OK, disregard my last comment. I've updated the question. All shells I tested are consistently outputting error messages. I also tried mksh -c '1(){ …;}' from last question in interactive mksh, which works, so that implies mksh being not entirely POSIX compliant in function declaration aspect. I wonder if that's something worth reporting to developers. – Sergiy Kolodyazhnyy Dec 17 '17 at 08:36
  • Nothing about it in the “Functions” section of MirOS Manual: mksh, however there's a POSIX mode you could try: set -o posix (see the hilarious FAQ at the end of the manual!) – dessert Dec 17 '17 at 09:08
  • @dessert nope, 1(){ echo "hi"; } works even in posix mode :/ – Sergiy Kolodyazhnyy Dec 17 '17 at 09:11

1 Answers1

2

Let me stress the relevant part:

a word consisting solely of underscores, digits, and alphabetics from the portable character set

Other characters in the portable character set are not allowed. Character being in the portable character set is a necessary, but not sufficient, condition.

muru
  • 197,895
  • 55
  • 485
  • 740