11

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?

1
  • 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 Commented Feb 5, 2015 at 14:16

1 Answer 1

12

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

Sign up to request clarification or add additional context in comments.

1 Comment

In the POSIX shell, a function name must consist solely of underscores and alphanumeric characters.