Skip to content
Advertisement

Bash script: too many arguments in [ test ]

I have the bash script below:

JavaScript

When I run it:

JavaScript

As you can see, when I don’t pass parameters ( $# -eq 0 ) it fails with “too many arguments”. So, I tested it directly in terminal:

JavaScript

So, if it works perfectly in terminal why doesn’t it work passing parameters?

Thanks,

Advertisement

Answer

Your entire expression can be simplified to:

JavaScript

This checks if the total sum of arguments is zero, or the argument(s) equals “–help”. If either of those two things are true then it proceeds to the help function, otherwise echo “done” and exit.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement