Re: associative arrays and [[ -v

2015-04-17 Thread isabella parakiss
(Sorry the previous message lacked the declaration of var, it was an asterisk obviously) $ var=* $ declare -A arr=([a]=b) $ [[ -v arr['$var'] ]]; echo $? 1 $ declare -A arr=(['*']=x) $ [[ -v arr['$var'] ]]; echo $? 0 --- xoxo iza On 4/18/15, isabella parakiss wrote: > On 4/17/15, Chet Ramey

Re: associative arrays and [[ -v

2015-04-17 Thread isabella parakiss
On 4/17/15, Chet Ramey wrote: > On 4/17/15 5:12 AM, isabella parakiss wrote: >> I need to check if an element in an associative array is set. What's the >> correct way to test it? > > If *any* element is set, or if a particular element is set? > >> >> >> $ declare -A arr=([x]=y); var=* >> $ [[ -v

Re: [Help-bash] make function local

2015-04-17 Thread Eduardo A . Bustamante López
Hey Linda. I do remember that thread, and I apologize for my words. I honestly try my best here. But it seems that I cannot reply to you without offending you, so, to avoid further offenses I will not reply to any further email from you in the future. I'm sorry that I offended you, it was not my

Re: [Help-bash] make function local

2015-04-17 Thread Linda Walsh
Eduardo A. Bustamante López wrote: Well, if your scripts are so simple, why use local functions at all? --- Cleanliness, Hygiene... You're claiming we invent stuff to make your examples fail, but I don't know anyone that writes such complex code for very simple tasks that can even b

[PATCH] Add EXECIGNORE

2015-04-17 Thread Eric Blake
Based on an idea from Dan Colascione: https://sourceware.org/ml/cygwin/2010-11/msg00022.html Usage: add this to your shell startup: EXECIGNORE='*.so:*.so.*' to cause TAB completion to ignore shared library files when crawling the file system to look for executables. Cygwin has been using a vari

Re: [Help-bash] make function local

2015-04-17 Thread Eduardo A . Bustamante López
Well, if your scripts are so simple, why use local functions at all? You're claiming we invent stuff to make your examples fail, but I don't know anyone that writes such complex code for very simple tasks that can even be done without functions. So, the burden to prove these convoluted approaches a

Re: [PATCH] circular buffer + hash for jobs.c:bgpids

2015-04-17 Thread John Fremlin
Did some benchmarks, for the while true; do (:) & (:); done simple example this goes from 215 to 313 iterations/s, and changes sys+user CPU from 152% to 45% Any long running bash script will tend to exhibit this issue -- On 4/15/15, 5:59 PM, "John Fremlin" wrote: >Over time, a long running bash

Re: [Help-bash] make function local

2015-04-17 Thread Linda Walsh
Greg Wooledge wrote: The problem is, ALL function definitions (and un-definitions) are global. --- yeah... If there was a "func" defined at the global scope, you've obliterated it. I don't understand why you don't understand this. --- I don't understand why you think I don't understa

Re: Multiple patches to fix compiler warnings

2015-04-17 Thread Eduardo A . Bustamante López
On Fri, Apr 17, 2015 at 04:26:08PM -0400, Mike Frysinger wrote: > please post patches inline and as a series rather than attaching a binary > tarball. it makes review much harder when you do this. > > in fact, `git send-email` takes care of all of this for you. > -mike Makes sense, thanks! I'll

Re: Multiple patches to fix compiler warnings

2015-04-17 Thread Mike Frysinger
please post patches inline and as a series rather than attaching a binary tarball. it makes review much harder when you do this. in fact, `git send-email` takes care of all of this for you. -mike signature.asc Description: Digital signature

Re: messy bash.git history

2015-04-17 Thread Eric Blake
On 02/06/2015 02:13 PM, Eric Blake wrote: > Chet, > > I've noticed that your 'devel' branch in bash.git is rather messy; > basically lots of commits that snapshot the state of a directory, then a > followup commit that removes leftovers and stray files. If you were to > set your .gitignore file (

Re: [Help-bash] make function local

2015-04-17 Thread Greg Wooledge
On Fri, Apr 17, 2015 at 11:58:15AM -0700, Linda Walsh wrote: > >outerfunc() { > > func() { ...; } > > func args > > unset -f func > >} > >outerfunc The problem is, ALL function definitions (and un-definitions) are global. If there was a "func" defined at the global scope, you've obliterated it. I

Re: [Help-bash] make function local

2015-04-17 Thread Linda Walsh
Eduardo A. Bustamante López wrote: On Thu, Apr 16, 2015 at 10:38:22PM -0700, Linda Walsh wrote: [...] AFAIK, _exec_gvim, can only be called from within "function gvim", no? No. Doing this: outerfunc() { func() { ...; } func args unset -f func } outerfunc Doesn't guarantee that `func' wi

Re: [Help-bash] make function local

2015-04-17 Thread Linda Walsh
Greg Wooledge wrote: AFAIK, _exec_gvim, can only be called from within "function gvim", no? That is not correct. In bash, all function definitions are global. imadev:~$ f1() { f2() { echo "I'm f2"; }; }; f1; f2 I'm f2 You left out a few important parts, like f2 being called inside f1

read() returns positive numbers in BSD systems, which make: bash / valid.

2015-04-17 Thread Eduardo A . Bustamante López
In the BSDs, doing a read on a directory doesn't return a negative value. Bash assumes that you can't do reads on directories here: 1501 /* Only do this with non-tty file descriptors we can seek on. */ 1502 if (fd_is_tty == 0 && (lseek (fd, 0L, 1) != -1)) 1503 { 1504 /* Check to see

Multiple patches to fix compiler warnings

2015-04-17 Thread Eduardo A . Bustamante López
0001-Fix-spacing-issues-in-tests-to-make-it-easier-to-tra.patch This one attempts to remove the false positives that the different spacing output between od's causes. There's also a change for one of the unicode tests, but I'm not sure about that one. 0002-Fix-unclosed-double-quote.patch This

Re: [PATCH] build: fix build of variables.c

2015-04-17 Thread Eric Blake
On 04/17/2015 11:42 AM, Eric Blake wrote: > On 04/17/2015 11:38 AM, Eric Blake wrote: >> On 04/17/2015 11:01 AM, Chet Ramey wrote: >>> On 4/17/15 10:26 AM, Eric Blake wrote: gcc -DPROGRAM='"bash"' -DCONF_HOSTTYPE='"x86_64"' -DCONF_OSTYPE='"linux-gnu"' -DCONF_MACHTYPE='"x86_64-unknown-li

Re: [PATCH] build: fix build without MALLOC_STATS

2015-04-17 Thread Eric Blake
On 04/17/2015 11:46 AM, Chet Ramey wrote: > On 4/17/15 10:47 AM, Eric Blake wrote: >> gcc -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob >> -L./lib/tilde -L./lib/malloc -L./lib/sh -rdynamic -g -O2 -Wno-parentheses >> -Wno-format-security -o bash shell.o eval.o y.tab.o general.o mak

Re: [PATCH] build: fix build of variables.c

2015-04-17 Thread Eric Blake
On 04/17/2015 11:38 AM, Eric Blake wrote: > On 04/17/2015 11:01 AM, Chet Ramey wrote: >> On 4/17/15 10:26 AM, Eric Blake wrote: >>> gcc -DPROGRAM='"bash"' -DCONF_HOSTTYPE='"x86_64"' >>> -DCONF_OSTYPE='"linux-gnu"' -DCONF_MACHTYPE='"x86_64-unknown-linux-gnu"' >>> -DCONF_VENDOR='"unknown"' -DLOCAL

Re: [PATCH] build: fix build without MALLOC_STATS

2015-04-17 Thread Chet Ramey
On 4/17/15 10:47 AM, Eric Blake wrote: > gcc -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob -L./lib/tilde > -L./lib/malloc -L./lib/sh -rdynamic -g -O2 -Wno-parentheses > -Wno-format-security -o bash shell.o eval.o y.tab.o general.o make_cmd.o > print_cmd.o dispose_cmd.o execute_c

Re: [PATCH] build: fix build of variables.c

2015-04-17 Thread Chet Ramey
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 4/17/15 1:38 PM, Eric Blake wrote: > On 04/17/2015 11:01 AM, Chet Ramey wrote: >> On 4/17/15 10:26 AM, Eric Blake wrote: >>> gcc -DPROGRAM='"bash"' -DCONF_HOSTTYPE='"x86_64"' >>> -DCONF_OSTYPE='"linux-gnu"' >>> -DCONF_MACHTYPE='"x86_64-unknown-linu

Re: [PATCH] build: fix build of variables.c

2015-04-17 Thread Eric Blake
On 04/17/2015 11:01 AM, Chet Ramey wrote: > On 4/17/15 10:26 AM, Eric Blake wrote: >> gcc -DPROGRAM='"bash"' -DCONF_HOSTTYPE='"x86_64"' >> -DCONF_OSTYPE='"linux-gnu"' -DCONF_MACHTYPE='"x86_64-unknown-linux-gnu"' >> -DCONF_VENDOR='"unknown"' -DLOCALEDIR='"/usr/local/share/locale"' >> -DPACKAGE='

Re: [PATCH] build: fix build of variables.c

2015-04-17 Thread Chet Ramey
On 4/17/15 10:26 AM, Eric Blake wrote: > gcc -DPROGRAM='"bash"' -DCONF_HOSTTYPE='"x86_64"' > -DCONF_OSTYPE='"linux-gnu"' -DCONF_MACHTYPE='"x86_64-unknown-linux-gnu"' > -DCONF_VENDOR='"unknown"' -DLOCALEDIR='"/usr/local/share/locale"' > -DPACKAGE='"bash"' -DSHELL -DHAVE_CONFIG_H -DDEBUG -DMALLOC

Re: associative arrays and [[ -v

2015-04-17 Thread Chet Ramey
On 4/17/15 9:10 AM, isabella parakiss wrote: > > Ok that kind of makes test -v useless, doesn't it? No, not really. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.c

Re: associative arrays and [[ -v

2015-04-17 Thread Chet Ramey
On 4/17/15 5:12 AM, isabella parakiss wrote: > I need to check if an element in an associative array is set. What's the > correct way to test it? If *any* element is set, or if a particular element is set? > > > $ declare -A arr=([x]=y); var=* > $ [[ -v arr["$var"] ]]; echo $? > 0 > $ [[ ${arr

Re: Bash performance when declaring variables

2015-04-17 Thread Eduardo A . Bustamante López
I agree 100% with you here. I don't see the point of optimizing bash for unrealistic cases. -- Eduardo Bustamante https://dualbus.me/

Re: Bash performance when declaring variables

2015-04-17 Thread Chet Ramey
On 4/16/15 12:48 PM, Eduardo A. Bustamante López wrote: > On Thu, Apr 16, 2015 at 11:07:34AM -0400, Chet Ramey wrote: > [...] >> I knew that rang a bell somewhere. mt_hash is a function in the bash >> malloc library that keeps track of all allocations and deallocations in >> a table. It's part of

[PATCH] build: fix build without MALLOC_STATS

2015-04-17 Thread Eric Blake
gcc -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob -L./lib/tilde -L./lib/malloc -L./lib/sh -rdynamic -g -O2 -Wno-parentheses -Wno-format-security -o bash shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o dispose_cmd.o execute_cmd.o variables.o copy_cmd.o error.o expr.o fla

[PATCH] build: fix build of variables.c

2015-04-17 Thread Eric Blake
gcc -DPROGRAM='"bash"' -DCONF_HOSTTYPE='"x86_64"' -DCONF_OSTYPE='"linux-gnu"' -DCONF_MACHTYPE='"x86_64-unknown-linux-gnu"' -DCONF_VENDOR='"unknown"' -DLOCALEDIR='"/usr/local/share/locale"' -DPACKAGE='"bash"' -DSHELL -DHAVE_CONFIG_H -DDEBUG -DMALLOC_DEBUG -I. -I. -I./include -I./lib -g -O2 -

Re: Incorrect manage "*" in test -z

2015-04-17 Thread Dennis Williamson
On Fri, Apr 17, 2015 at 8:55 AM, Eduardo A. Bustamante López < dual...@gmail.com> wrote: > > Always quote your variables. The problem comes from > > > > echo $INPUT > > > > which should be > > > > echo $INPUT > > Someone derped. It *should* be > > echo "$INPUT" > > -- > Eduardo Bustamante > https

Re: Incorrect manage "*" in test -z

2015-04-17 Thread Eduardo A . Bustamante López
> Always quote your variables. The problem comes from > > echo $INPUT > > which should be > > echo $INPUT Someone derped. It *should* be echo "$INPUT" -- Eduardo Bustamante https://dualbus.me/

Re: test whether array variable is set with ${parameter:+word}

2015-04-17 Thread Eduardo A . Bustamante López
This is not a bug. This is due to not understanding two aspects of bash: 1) $arrname is the same as ${arrname[0]} (not the "first" element, as what you seem to imply). Bash arrays are sparse, so you can define the element at index 1, without having an element at 0. 2) unset and empty is not

Re: associative arrays and [[ -v

2015-04-17 Thread Eduardo A . Bustamante López
> Ok that kind of makes test -v useless, doesn't it? You might want to read: https://lists.gnu.org/archive/html/bug-bash/2014-11/msg00099.html -- Eduardo Bustamante https://dualbus.me/

test whether array variable is set with ${parameter:+word}

2015-04-17 Thread pphick
Configuration Information [Automatically generated, do not change]: Machine: i686 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/b/home/share/locale' -DPACKAGE=

Re: Incorrect manage "*" in test -z

2015-04-17 Thread Dennis Williamson
On Thu, Apr 16, 2015 at 6:51 PM, Guillermo Buritica Tobon < gburitic...@gmail.com> wrote: > Hi All. > > H have the next bash script code.: > > #!/bin/sh > # Pring OK on empty input, > # Print input on non-empty input > > read INPUT > if [ -z "$INPUT" ]; then > echo OK > else > echo

Re: associative arrays and [[ -v

2015-04-17 Thread isabella parakiss
On 4/17/15, Eduardo A. Bustamante López wrote: > On Fri, Apr 17, 2015 at 11:12:50AM +0200, isabella parakiss wrote: >> I need to check if an element in an associative array is set. What's the >> correct way to test it? > > dualbus@yaqui ~ % export key; for key in \* x y; do bash -c 'declare -A >

Re: [Help-bash] make function local

2015-04-17 Thread Eduardo A . Bustamante López
On Thu, Apr 16, 2015 at 10:38:22PM -0700, Linda Walsh wrote: [...] > AFAIK, _exec_gvim, can only be called from within "function gvim", no? No. Doing this: outerfunc() { func() { ...; } func args unset -f func } outerfunc Doesn't guarantee that `func' will be only called from outerfunc. If yo

Re: associative arrays and [[ -v

2015-04-17 Thread Eduardo A . Bustamante López
On Fri, Apr 17, 2015 at 11:12:50AM +0200, isabella parakiss wrote: > I need to check if an element in an associative array is set. What's the > correct way to test it? dualbus@yaqui ~ % export key; for key in \* x y; do bash -c 'declare -A a=([x]=y [y]=); echo "$key" ${a[$key]+inarray}; declare

Re: [Help-bash] make function local

2015-04-17 Thread Greg Wooledge
On Thu, Apr 16, 2015 at 10:38:22PM -0700, Linda Walsh wrote: > It's a trite example, but I do something like: > > > sub gvim () { > array orig_args=($@) gv_files=() gv_ops=() > int use_tab=0 look_for_ops=1 > >sub _exec_gvim() { > array args > ((use_tab)) && args=("-p") > (

Re: Incorrect manage "*" in test -z

2015-04-17 Thread Greg Wooledge
On Fri, Apr 17, 2015 at 09:51:04AM +1000, Guillermo Buritica Tobon wrote: > H have the next bash script code.: > > #!/bin/sh This is not bash. This is sh. > read INPUT Avoid using ALL-CAPS variable names. All-caps names are reserved for internal shell variables, and environment variables like

associative arrays and [[ -v

2015-04-17 Thread isabella parakiss
I need to check if an element in an associative array is set. What's the correct way to test it? $ declare -A arr=([x]=y); var=* $ [[ -v arr["$var"] ]]; echo $? 0 $ [[ ${arr["$var"]} ]]; echo $? 1 The former seems wrong, the glob is expanded even if "$var" is quoted. The latter works but it do