Re: Error in bash documentation for builtin declare
On 11/6/20 12:21 PM, Edouard Thiel wrote: >>> By the way, I have seen that the nameref works more or less for functions: >>> $ foo() { echo "hello" ;} >>> $ declare -n bar=foo >>> but the reference has to be dereferenced when calling: >>> $ ${!bar} >>> hello >>> >>> is it still the case in bash 5? >> Sure, it seems harmless to allow it. > I mean, I was surprised I couldn't simply run > $ bar What would be reasonable to expect that to do? There's no word expansion, so no opportunity to perform any kind of nameref expansion. You can either use namerefs as you did above, or have no nameref attribute and use ${bar}. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
Re: Error in bash documentation for builtin declare
Le 06/11/2020 à 18:06, Chet Ramey a écrit : On 11/6/20 11:53 AM, Edouard Thiel wrote: This is more clear, and in fact, ok for me (if subscripted means associative?); the link above is not up to date. The same language appears in the "Shell Parameters" section of the manual at the above link, just as it does in the "PARAMETERS" section of the manual page. in fact, I didn't see this. The #Bash-Builtins section misled me. Sorry! By the way, I have seen that the nameref works more or less for functions: $ foo() { echo "hello" ;} $ declare -n bar=foo but the reference has to be dereferenced when calling: $ ${!bar} hello is it still the case in bash 5? Sure, it seems harmless to allow it. I mean, I was surprised I couldn't simply run $ bar thanks for your fast responses Cheers, Edouard PS I love teaching bash :) -- Professeur Edouard THIEL http://j.mp/ethiel Département Informatique et Interactions http://j.mp/dept-ii UFR Sciences, Aix-Marseille Universitéhttp://j.mp/fs-amu Laboratoire d'Informatique et Systèmeshttp://j.mp/lis-amu
Re: Error in bash documentation for builtin declare
On 11/6/20 11:53 AM, Edouard Thiel wrote: > > > Le 06/11/2020 à 17:01, Greg Wooledge a écrit : >> On Fri, Nov 06, 2020 at 02:07:36PM +0100, Edouard Thiel wrote: >>> there is an error in the bash documentation: >>> https://www.gnu.org/software/bash/manual/bash.html#Bash-Builtins >>> >>> In the 'declare' builtin, option '-n', last sentence: >>> "The nameref attribute cannot be applied to array variables" >>> is actually wrong: it can be applied to indexed and associative arrays >>> (since bash 4.3+) >>> >>> (tested for bash version : 4.3.48(1)-release (x86_64-pc-linux-gnu)) >> The relevant section in the 5.0 man page under PARAMETERS says: >> >> Array variables cannot be given the nameref attribute. However, >> nameref variables can reference array variables and subscripted >> array variables. >> >> What, exactly, did you test? > This is more clear, and in fact, ok for me (if subscripted means > associative?); > the link above is not up to date. The same language appears in the "Shell Parameters" section of the manual at the above link, just as it does in the "PARAMETERS" section of the manual page. > > By the way, I have seen that the nameref works more or less for functions: > $ foo() { echo "hello" ;} > $ declare -n bar=foo > but the reference has to be dereferenced when calling: > $ ${!bar} > hello > > is it still the case in bash 5? Sure, it seems harmless to allow it. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
Re: Error in bash documentation for builtin declare
Le 06/11/2020 à 17:01, Greg Wooledge a écrit : On Fri, Nov 06, 2020 at 02:07:36PM +0100, Edouard Thiel wrote: there is an error in the bash documentation: https://www.gnu.org/software/bash/manual/bash.html#Bash-Builtins In the 'declare' builtin, option '-n', last sentence: "The nameref attribute cannot be applied to array variables" is actually wrong: it can be applied to indexed and associative arrays (since bash 4.3+) (tested for bash version : 4.3.48(1)-release (x86_64-pc-linux-gnu)) The relevant section in the 5.0 man page under PARAMETERS says: Array variables cannot be given the nameref attribute. However, nameref variables can reference array variables and subscripted array variables. What, exactly, did you test? This is more clear, and in fact, ok for me (if subscripted means associative?); the link above is not up to date. By the way, I have seen that the nameref works more or less for functions: $ foo() { echo "hello" ;} $ declare -n bar=foo but the reference has to be dereferenced when calling: $ ${!bar} hello is it still the case in bash 5? Cheers, Edouard -- Professeur Edouard THIEL http://j.mp/ethiel Département Informatique et Interactions http://j.mp/dept-ii UFR Sciences, Aix-Marseille Universitéhttp://j.mp/fs-amu Laboratoire d'Informatique et Systèmeshttp://j.mp/lis-amu
Re: Error in bash documentation for builtin declare
On 11/6/20 8:07 AM, Edouard Thiel wrote: > Hello, > > there is an error in the bash documentation: > https://www.gnu.org/software/bash/manual/bash.html#Bash-Builtins > > In the 'declare' builtin, option '-n', last sentence: > "The nameref attribute cannot be applied to array variables" > is actually wrong: it can be applied to indexed and associative arrays > (since bash 4.3+) Is this what you mean, or something else? $ cat x3 echo $BASH_VERSION declare -a foo=(a b c) declare -n foo declare -A bar=( [one]=1 [two]=2 ) declare -n bar declare -an flip=(a b c) declare -An flop=( [one]=1 [two]=2 ) declare -p foo bar flip flop $ ../bash-5.0-patched/bash x3 5.0.18(9)-release x3: line 4: declare: foo: reference variable cannot be an array x3: line 7: declare: bar: reference variable cannot be an array x3: line 9: declare: flip: reference variable cannot be an array x3: line 10: declare: flop: reference variable cannot be an array declare -a foo=([0]="a" [1]="b" [2]="c") declare -A bar=([two]="2" [one]="1" ) declare -a flip=([0]="a" [1]="b" [2]="c") declare -A flop=([two]="2" [one]="1" ) -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
Re: Error in bash documentation for builtin declare
On Fri, Nov 06, 2020 at 02:07:36PM +0100, Edouard Thiel wrote: > there is an error in the bash documentation: > https://www.gnu.org/software/bash/manual/bash.html#Bash-Builtins > > In the 'declare' builtin, option '-n', last sentence: > "The nameref attribute cannot be applied to array variables" > is actually wrong: it can be applied to indexed and associative arrays > (since bash 4.3+) > > (tested for bash version : 4.3.48(1)-release (x86_64-pc-linux-gnu)) The relevant section in the 5.0 man page under PARAMETERS says: Array variables cannot be given the nameref attribute. However, nameref variables can reference array variables and subscripted array variables. What, exactly, did you test?
Error in bash documentation for builtin declare
Hello, there is an error in the bash documentation: https://www.gnu.org/software/bash/manual/bash.html#Bash-Builtins In the 'declare' builtin, option '-n', last sentence: "The nameref attribute cannot be applied to array variables" is actually wrong: it can be applied to indexed and associative arrays (since bash 4.3+) (tested for bash version : 4.3.48(1)-release (x86_64-pc-linux-gnu)) it can even be applied to functions, except that for calling, explicit dereference must be given. Cheers, Edouard Thiel -- Professeur Edouard THIEL http://j.mp/ethiel Département Informatique et Interactions http://j.mp/dept-ii UFR Sciences, Aix-Marseille Universitéhttp://j.mp/fs-amu Laboratoire d'Informatique et Systèmeshttp://j.mp/lis-amu