Op 28-12-18 om 01:39 schreef Peng Yu:
What I meant in my original email is that I want something for testing
if there is a command line argument (one or more, the exact number
does not matter). $# gives more than that info, because it tells not
only whether is any command line argument, but also how many. This
could lead to slower performance if the goal is to just test if there
is an argument.
I don't believe that at all. The number of positional parameters is kept
anyway. It's not recalculated when you compare it to another number, so
it's just as fast as a simple comparison of two integers.
[[ -z ${1+s} ]] does something also more than necessary too, because
it not only tests for whether $1 is set, it also replaced with a
string "s". This also does more than just testing whether $1 is set.
That's negligible.
And even if it weren't -- if performance is *that* important to you,
you're using the wrong language altogether.
- M.