10

While playing around with bash and sh, I found out that the following is valid in bash:

system.out.println () { printf "$1"; }

but not in sh:

sh: `system.out.println': not a valid identifier

Why would this difference be there? Does the function defined above violate some convention (POSIX etc.) that causes this error?

  • While I'm not sure this will solve your problem, you could try using aliases. Like this: ldot_function () { ls -A $* | egrep '^\.' } alias l.=ldot_function – Cyberwiz Feb 05 '15 at 14:16

1 Answers1

11

It's just the dots, you can't use dots in shell function names. Or any variable name, for that matter.

I'll link you to this question: Allowed characters in linux environment variable names

Community
  • 1
  • 1
Noctua
  • 5,058
  • 1
  • 18
  • 23
  • 7
    In the POSIX shell, a function [name](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_231) must consist solely of underscores and alphanumeric characters. – chepner Dec 25 '13 at 21:38