Use smart semantics
The key is the readability and intent of your code. If you have no reason for this, you probably just want to determine the length of the parameter list.
# Is length of parameter list equal to zero? [ $# -eq 0 ]
However, you can use any extension or parameter comparison operator that expresses the intent of your code. There is no right way to do this, but you can of course think about the portability of the semantics of your test.
Food for thought
This is not a conditional expression, which is inherently important. What is important, why you want to know. For instance:
set -e foo="$1" shift
In this case, the length of the parameter list is never checked directly. The first parameter is simply assigned (even if it can be canceled), and then the shell throws an error and exits when you try to move the parameter list. This code says: "I just expect the parameters to be there, I would not have to check them explicitly."
The point is that you need to determine what your code is trying to express and match the semantics of your tests and conventions to express it as clearly as you can. There is actually no orthogonal answer.
source share