3

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
  • 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

3

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
  • 207,970
  • Well, this is just slightly annoying that every word in the standard has to be interpreted. – Sergiy Kolodyazhnyy Dec 17 '17 at 05:07
  • 2
    @SergiyKolodyazhnyy :D and yet your question is a perfect example of why they have to be so precise in their wording. You might find this to be of interest: https://stackoverflow.com/tags/language-lawyer/info – muru Dec 17 '17 at 05:09
  • pity there's no such tag on AU – Sergiy Kolodyazhnyy Dec 17 '17 at 05:11
  • It would be so marvelous if POSIX would also allow dots and/or colons in some name like functions since those are always global, and if you source a "library" it generally overwrites it. With names like regex::process instead of process, regex_process, _regex_process, __regex_process, ___regex_process, Regex_process etc. – Serious Angel Jul 26 '24 at 09:37