Re: test -v for array does not work as documented
On 2/21/20 3:31 AM, pepa65 wrote: > On 21/02/2020 02.37, Chet Ramey wrote: >> It's unset because it doesn't have a value, but it retains the `local' >> attribute so it stays local if subsequently assigned one. > > Is there any reason the local attribute cannot be unset? If it would be > possible then the "declare/typeset -p" would return 1 when the variable > doesn't exist. There have been several umm...passionate discussions about this. The idea is that a local variable that's unset should stay local (and unset) until the function returns instead of `uncovering' a variable at a previous scope. Think about dynamic scoping and its effects on variable visibility. > By the way, it seems that `local -p var` doesn't work like 'declare -p > var` even though `help local` suggests it should. How so? Do you mean that declare -p var in a function will show different variables? -- ``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: test -v for array does not work as documented
On 23/02/2020 23.27, Chet Ramey wrote: > On 2/21/20 3:31 AM, pepa65 wrote: >> By the way, it seems that `local -p var` doesn't work like 'declare -p >> var` even though `help local` suggests it should. > > How so? Do you mean that declare -p var in a function will show different > variables? See this output: localvsdeclare(){ local var var=42 unset var echo -n '"declare -p var":' declare -p var echo -n '"local -p var":' local -p var } localvsdeclare "declare -p var": declare -- var "local -p var": Peter
Re: test -v for array does not work as documented
On 2/23/20 11:36 AM, pepa65 wrote: > On 23/02/2020 23.27, Chet Ramey wrote: >> On 2/21/20 3:31 AM, pepa65 wrote: >>> By the way, it seems that `local -p var` doesn't work like 'declare -p >>> var` even though `help local` suggests it should. >> >> How so? Do you mean that declare -p var in a function will show different >> variables? > > See this output: > > localvsdeclare(){ > local var > var=42 > unset var > echo -n '"declare -p var":' > declare -p var > echo -n '"local -p var":' > local -p var > } > > localvsdeclare > "declare -p var": declare -- var > "local -p var": Yes, it's always been this way. This behavior dates to March, 1995, literally to the time I added `-p'. The reason for not making `local -p' work the same has been lost to time, so let's try making it the same and see what happens. -- ``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: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a
On 2/20/20 7:34 PM, Arfrever Frehtes Taifersar Arahesis wrote: >> Same answer as previously: maybe it should display the attributes >> even thought the variable is unset. > > Yes, I think that @A, [@]@A, @a and [@]@a should work for unset variables. OK, we'll try that and see how it works. -- ``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/