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

2018-12-27 Thread Chet Ramey
On 12/26/18 10:49 PM, Peng Yu wrote: > Although [[ -z ${1+s} ]] and (($#)) works for testing if $1 is set, > neither of them are uniformly better performance wise. In this case, > should [[ -v 1 ]] be supported? So you're saying that neither of the existing options performs better than the other

Re: How to compile hashlib.c for testing?

2018-12-27 Thread Chet Ramey
On 12/26/18 4:31 PM, Peng Yu wrote: > Hi, > > I'd like to compile hashlib.c to try its main(). But I got the > following error. What is the correct commands to compile it? Thanks. Think about the error message: > "_xmalloc", referenced from: > _hash_create in hashlib.o > _hash_copy

Re: [Help-bash] Why does ctrl-c behave differently for builtin sleep in a subshell?

2018-12-27 Thread Chet Ramey
On 12/25/18 11:28 AM, Peng Yu wrote: > If I add a command after the builtin sleep, then the EXIT trap will be > triggered upon typing ctrl-C. > > If the last command is removed, then the EXIT trap will not be > triggered upon typing ctrl-C. It's a bug in bash-4.4, fixed in bash-5.0. -- ``The l

Re: Error on arithmetic evaluation of `~0`.

2018-12-27 Thread konsolebox
Simple variables convert to array variables dynamically, but that doesn't mean they should be interpreted exactly as if they are. I see that more of just a convenient feature. On Mon, Dec 24, 2018, 1:02 AM Bize Ma Chet Ramey () wrote: > > > > > > > While this works: > > > > > > var=(hello); echo

Re: difference between /tmp and other directory for loadable mkdir?

2018-12-27 Thread Chet Ramey
On 12/26/18 2:56 PM, Eduardo A. Bustamante López wrote: > On Wed, Dec 26, 2018 at 12:40:09PM -0600, Peng Yu wrote: >> Hi, >> >> I can not mkdir -p . in /tmp/ via the loadable mkdir. What is the >> difference between /tmp/ and other directories? I am on Mac OS X. Is >> this a bug in mkdir? The diff

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

2018-12-27 Thread Martijn Dekker
Op 27-12-18 om 19:22 schreef Chet Ramey: On 12/26/18 10:49 PM, Peng Yu wrote: Although [[ -z ${1+s} ]] and (($#)) works for testing if $1 is set, neither of them are uniformly better performance wise. In this case, should [[ -v 1 ]] be supported? So you're saying that neither of the existing

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

2018-12-27 Thread Peng Yu
On Thu, Dec 27, 2018 at 3:19 PM Martijn Dekker wrote: > > Op 27-12-18 om 19:22 schreef Chet Ramey: > > On 12/26/18 10:49 PM, Peng Yu wrote: > > > >> Although [[ -z ${1+s} ]] and (($#)) works for testing if $1 is set, > >> neither of them are uniformly better performance wise. In this case, > >> s

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

2018-12-27 Thread Eduardo Bustamante
On Thu, Dec 27, 2018 at 4:50 PM Peng Yu wrote: (...) > 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 li

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

2018-12-27 Thread Martijn Dekker
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

Re: How to compile hashlib.c for testing?

2018-12-27 Thread Peng Yu
On Thu, Dec 27, 2018 at 12:27 PM Chet Ramey wrote: > > On 12/26/18 4:31 PM, Peng Yu wrote: > > Hi, > > > > I'd like to compile hashlib.c to try its main(). But I got the > > following error. What is the correct commands to compile it? Thanks. > > Think about the error message: > > > "_xmalloc",

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

2018-12-27 Thread G. Branden Robinson
At 2018-12-27T18:39:26-0600, Peng Yu wrote: > 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 argumen

Re: How to compile hashlib.c for testing?

2018-12-27 Thread Eduardo Bustamante
On Thu, Dec 27, 2018 at 5:15 PM Peng Yu wrote: (...) > Since the main() function is already there, why there is not already > an easy way to compile it? How do you do unit-testing then for the > code? This is very easy to figure out from the source code, right :)? (Hint: there is no "unit" testi

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

2018-12-27 Thread Peng Yu
> 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. Getting the number $# is slow. > And even if it weren't -- if performance is *that* impo

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

2018-12-27 Thread G. Branden Robinson
At 2018-12-27T19:24:22-0600, Peng Yu wrote: > > 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. > > Getting the number $# is slow. By

Re: How to compile hashlib.c for testing?

2018-12-27 Thread G. Branden Robinson
At 2018-12-27T17:34:49-0800, Eduardo Bustamante wrote: > On Thu, Dec 27, 2018 at 5:15 PM Peng Yu wrote: > (...) > > Since the main() function is already there, why there is not already > > an easy way to compile it? How do you do unit-testing then for the > > code? > > This is very easy to figure

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

2018-12-27 Thread G. Branden Robinson
At 2018-12-27T19:47:08-0600, Peng Yu wrote: > On Thu, Dec 27, 2018 at 7:37 PM G. Branden Robinson > > As others have noted, if you are worried about marginal performance > > impacts this small, margin you are probably writing in the wrong > > language, or distracting yourself with tiny details when

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

2018-12-27 Thread Eduardo Bustamante
On Thu, Dec 27, 2018 at 5:38 PM Peng Yu wrote: > > > 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. > > Getting the number $# is slow.

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

2018-12-27 Thread Peng Yu
On Thu, Dec 27, 2018 at 7:37 PM G. Branden Robinson wrote: > > At 2018-12-27T18:39:26-0600, Peng Yu wrote: > > 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

Re: How to compile hashlib.c for testing?

2018-12-27 Thread Peng Yu
We are talking about unit testing in the bash C source code, not bash scripts. On Thu, Dec 27, 2018 at 8:03 PM G. Branden Robinson wrote: > > At 2018-12-27T17:34:49-0800, Eduardo Bustamante wrote: > > On Thu, Dec 27, 2018 at 5:15 PM Peng Yu wrote: > > (...) > > > Since the main() function is alr

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

2018-12-27 Thread Peng Yu
> You're whacking moles. Use a profiler. That's what they're for. I've already shown that $() is a major problem to slow down the speed and I have reduced using its usage in my code and significantly improved the performance. Nevertheless, it doesn't mean that it is not necessary to systematical

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

2018-12-27 Thread Eduardo Bustamante
On Thu, Dec 27, 2018 at 9:45 PM Peng Yu wrote: (...) > Yes and no. For a particular bash script, you can quantify which bash > features are the most time-consuming. (...) > (...) But you can not profile all the > bash scripts that have ever been written. Since there are only limited > features in

Re: How to compile hashlib.c for testing?

2018-12-27 Thread Pierre Gaston
On Fri, Dec 28, 2018 at 4:28 AM Peng Yu wrote: > We are talking about unit testing in the bash C source code, not bash > scripts. > While toying with the loadable builtins I came up with this: https://github.com/pgas/newt_builtin/blob/master/make.libbash you need to set BASH_PATH so that it p