bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should [[ -v 1 ]] be supported?


From: Martijn Dekker
Subject: Re: Should [[ -v 1 ]] be supported?
Date: Fri, 28 Dec 2018 02:08:19 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]