Space literal as function name in bash

Tags:

Answer: 1

30 hours ago

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
Added by: Max Leffler Jr.

Answer: 2

14 hours ago

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.

Popular Search

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9