How to initialize a read-only, global, associative array in Bash?

2012-11-26 Thread Tim Friske
Hi folks, I execute the following code in Bash version "GNU bash, Version 4.2.39(1)-release (x86_64-redhat-linux-gnu)": function foobar { declare -rgA FOOBAR=([foo]=bar) } foobar declare -p FOOBAR # Output: declare -Ar FOOBAR='()' Why doesn't Bash initialize FOOBAR with ([foo]=bar) according t

Why is not every variable initialized to its data type specific default value upon declaration in Bash?

2012-11-27 Thread Tim Friske
Hi folks, when I execute the following code in Bash version "GNU bash, version 4.1.10(4)-release (i686-pc-cygwin)", I get: declare a declare -p a # Output: -bash: declare: a: not found declare -i b declare -p b # Output: -bash: declare: b: not found declare -a c declare -p c # Output: declare -a

How to presence-detect an array variable or subscript thereof with `test -v`?

2012-11-27 Thread Tim Friske
Hi folks, I came accross the `-v` option of the `test` command and wondered how I would possibly test not only string- and integer- but also array variables as a whole and in parts. I thought it should be possible to say: declare -Ai foobar=([bar]=0) test -v foobar[foo] && echo true || echo fals

Strange re-initialization of array. Bug or feature?

2012-11-27 Thread Tim Friske
Hi folks, I execute the following code with Bash version "GNU bash, Version 4.2.39(1)-release (x86_64-redhat-linux-gnu)" on Fedora 17: # Returns 0 else 1 if the sourcing (source) script isn't keyed by its base name in the global "ONCE" array yet. # # A script should include this script near the t

Why can't I say "&>&3"? Bug or feature?

2012-12-06 Thread Tim Friske
Hi folks, why is it that I can't say: exec 3>/dev/null echo foobar &>&3 # Error: "-bash: syntax error near unexpected token `&'" but the following works: echo foobar &>/dev/null echo foobar >&3 2>&3 I think the succinct notation "&>&N" where N is some numbered file descriptor should work also.

Bash's declare -p HISTIGNORE brings bash to a halt! Why?

2014-01-11 Thread Tim Friske
Hi, executing the following code in GNU bash, Version 4.2.45(1)-release (x86_64-redhat-linux-gnu), Fedora 19 ... shopt -s extglob export HISTIGNORE="!(+(!([[\:space\:]]))+([[\:space\:]])+(!([[\:space\:]])))" declare -p HISTIGNORE ... brings bash to a full stop. It does not print a c

Re: Bash's declare -p HISTIGNORE brings bash to a halt! Why?

2014-01-11 Thread Tim Friske
/home/tifr/.cache/bash/history" Any ideas as to how to correctly assign the "+([^[:space:]])" pattern to the "HISTIGNORE" variable? By the way I'm setting the history related variables from my ".bash_login" file. That is why I'm exporting them. Than

Re: Bash's declare -p HISTIGNORE brings bash to a halt! Why?

2014-01-11 Thread Tim Friske
nvince bash's history with the following definitions: 1.) HISTIGNORE="+([[:word:]])" 2.) HISTIGNORE="+([^[:space:]])" On the other hand such simple definitions work: 1.) HISTIGNORE="+([a-z])" 2.) HISTIGNORE="+([-0-9A-Z_a-z])" Best regards Tim 2014/1/12 T

Possible bug when combining Bash's process substitution with HERE-document?

2014-06-17 Thread Tim Friske
Hi, see my question http://unix.stackexchange.com/questions/137506/how-to-combine-bashs-process-substitution-with-here-document for a description. Could the described behavior be a bug? Kind regards Tim

Re: Possible bug when combining Bash's process substitution with HERE-document?

2014-06-19 Thread Tim Friske
Hi, first I want to thank you for your help. While searching for an alternative I came up with the following code which does not work when I have the "shopt -os errexit" command line at the top of my script: read -d '' -r foobar <: > On 6/18/14, 4:27 PM, Dan Douglas wrote: >> On Wed, Jun 18, 201

Bug or feature: Why does Bash's "printf" define global variables?

2014-08-03 Thread Tim Friske
Hi, my assumption was that Bash's "printf" builtin implicitly defines a local variable when used inside a function like so: function foobar { printf -v foo bar; } foobar declare -p foo # Prints "bar" from the global "foo" variable. But instead I have to declare the "foo" variable

Feature request: Add "import" built-in.

2014-08-24 Thread Tim Friske
Hi, as I see it the "source" built-in is perfect for embedding a sourced Bash script into the sourcing one while preserving as much of the environment, specifically the positional and special parameters, as possible. What I am missing is the "import" built-in that passes only the explicitly given

declare -p my_function does not print its definition. A bug?

2014-10-18 Thread Tim Friske
Hi, when I define the following function: $ function foo { > echo bar > } and try to run it, I get: $ foo bar but try to print its definition with "declare", I get: $ declare -p foo bash: declare: foo: not found $ declare -pf foo bash: declare: foo: not found $declare -pF