BASH: syntax error near unexpected token `('

Sakis Kasampallis | Apr 19, 2014 min read
After making some portability and readability improvements to shell-utils, I used BASH, sh, and dash to test it. While sh and dash were fine, BASH returned the error:

line 358: syntax error near unexpected token `('
line 358: `ls ()'

That is strange. BASH usually introduces shell portability issues because of the extra features it provides, so I would expect to have a problem with the other shells.

It turns out that BASH did a pretty good job with reporting the source of the error. Note that shell-utils redefines a few everyday commands as functions, to make them more verbose and secure safe (eg. ls becomes ls --color=auto, rm becomes rm -i, etc.). But usually those everyday commands are already defined as aliases in .bashrc. Aliases are evaluated before functions, and defining a function that has the same name as an alias is not allowed. And that's what BASH is trying to tell me in the error message. Commenting all aliases in .bashrc fixed the issue :)